use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class Analyzer method analyzeNonStdOutSink.
private void analyzeNonStdOutSink() {
List<Pair<StructuredDataSource, String>> fromDataSources = analysis.getFromDataSources();
StructuredDataSource intoStructuredDataSource = analysis.getInto();
String intoKafkaTopicName = analysis.getIntoKafkaTopicName();
if (intoKafkaTopicName == null) {
intoKafkaTopicName = intoStructuredDataSource.getName();
}
KsqlTopicSerDe intoTopicSerde = fromDataSources.get(0).getLeft().getKsqlTopic().getKsqlTopicSerDe();
if (analysis.getIntoFormat() != null) {
switch(analysis.getIntoFormat().toUpperCase()) {
case DataSource.AVRO_SERDE_NAME:
intoTopicSerde = new KsqlAvroTopicSerDe();
break;
case DataSource.JSON_SERDE_NAME:
intoTopicSerde = new KsqlJsonTopicSerDe();
break;
case DataSource.DELIMITED_SERDE_NAME:
intoTopicSerde = new KsqlDelimitedTopicSerDe();
break;
default:
throw new KsqlException(String.format("Unsupported format: %s", analysis.getIntoFormat()));
}
} else {
if (intoTopicSerde instanceof KsqlAvroTopicSerDe) {
intoTopicSerde = new KsqlAvroTopicSerDe();
}
}
KsqlTopic newIntoKsqlTopic = new KsqlTopic(intoKafkaTopicName, intoKafkaTopicName, intoTopicSerde);
KsqlStream intoKsqlStream = new KsqlStream(sqlExpression, intoStructuredDataSource.getName(), null, null, null, newIntoKsqlTopic);
analysis.setInto(intoKsqlStream);
}
use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class Analyzer method visitAliasedRelation.
@Override
protected Node visitAliasedRelation(AliasedRelation node, AnalysisContext context) {
String structuredDataSourceName = ((Table) node.getRelation()).getName().getSuffix();
if (metaStore.getSource(structuredDataSourceName) == null) {
throw new KsqlException(structuredDataSourceName + " does not exist.");
}
StructuredDataSource structuredDataSource = metaStore.getSource(structuredDataSourceName);
if (((Table) node.getRelation()).getProperties() != null) {
if (((Table) node.getRelation()).getProperties().get(DdlConfig.TIMESTAMP_NAME_PROPERTY) != null) {
String timestampFieldName = ((Table) node.getRelation()).getProperties().get(DdlConfig.TIMESTAMP_NAME_PROPERTY).toString().toUpperCase();
if (!timestampFieldName.startsWith("'") && !timestampFieldName.endsWith("'")) {
throw new KsqlException("Property name should be String with single qoute.");
}
timestampFieldName = timestampFieldName.substring(1, timestampFieldName.length() - 1);
structuredDataSource = structuredDataSource.cloneWithTimeField(timestampFieldName);
}
}
Pair<StructuredDataSource, String> fromDataSource = new Pair<>(structuredDataSource, node.getAlias());
analysis.addDataSource(fromDataSource);
return node;
}
use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class SchemaKStream method createSelectValueMapperAndSchema.
Pair<Schema, SelectValueMapper> createSelectValueMapperAndSchema(final List<Pair<String, Expression>> expressionPairList) {
try {
final CodeGenRunner codeGenRunner = new CodeGenRunner(schema, functionRegistry);
final SchemaBuilder schemaBuilder = SchemaBuilder.struct();
final List<ExpressionMetadata> expressionEvaluators = new ArrayList<>();
for (Pair<String, Expression> expressionPair : expressionPairList) {
final ExpressionMetadata expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(expressionPair.getRight());
schemaBuilder.field(expressionPair.getLeft(), expressionEvaluator.getExpressionType());
expressionEvaluators.add(expressionEvaluator);
}
return new Pair<>(schemaBuilder.build(), new SelectValueMapper(genericRowValueTypeEnforcer, expressionPairList, expressionEvaluators));
} catch (Exception e) {
throw new KsqlException("Code generation failed for SelectValueMapper", e);
}
}
use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class TestUtils method getAllPriorCommandRecords.
public List<Pair<CommandId, Command>> getAllPriorCommandRecords() {
List<Pair<CommandId, Command>> priorCommands = new ArrayList<>();
Command topicCommand = new Command("REGISTER TOPIC pageview_topic WITH " + "(value_format = 'json', " + "kafka_topic='pageview_topic_json');", new HashMap<>());
CommandId topicCommandId = new CommandId(CommandId.Type.TOPIC, "_CSASTopicGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(topicCommandId, topicCommand));
Command csCommand = new Command("CREATE STREAM pageview " + "(viewtime bigint, pageid varchar, userid varchar) " + "WITH (registered_topic = 'pageview_topic');", new HashMap<>());
CommandId csCommandId = new CommandId(CommandId.Type.STREAM, "_CSASStreamGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(csCommandId, csCommand));
Command csasCommand = new Command("CREATE STREAM user1pv " + " AS select * from pageview WHERE userid = 'user1';", new HashMap<>());
CommandId csasCommandId = new CommandId(CommandId.Type.STREAM, "_CSASGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(csasCommandId, csasCommand));
Command ctasCommand = new Command("CREATE TABLE user1pvtb " + " AS select * from pageview window tumbling(size 5 " + "second) WHERE userid = " + "'user1' group by pageid;", new HashMap<>());
CommandId ctasCommandId = new CommandId(CommandId.Type.TABLE, "_CTASGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(ctasCommandId, ctasCommand));
return priorCommands;
}
Aggregations