use of org.apache.kafka.connect.data.SchemaBuilder 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 org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class LogicalPlanner method buildAggregateNode.
private AggregateNode buildAggregateNode(final Schema inputSchema, final PlanNode sourcePlanNode) {
SchemaBuilder aggregateSchema = SchemaBuilder.struct();
ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(inputSchema, functionRegistry);
for (int i = 0; i < analysis.getSelectExpressions().size(); i++) {
Expression expression = analysis.getSelectExpressions().get(i);
String alias = analysis.getSelectExpressionAlias().get(i);
Schema expressionType = expressionTypeManager.getExpressionType(expression);
aggregateSchema = aggregateSchema.field(alias, expressionType);
}
return new AggregateNode(new PlanNodeId("Aggregate"), sourcePlanNode, aggregateSchema, analysis.getGroupByExpressions(), analysis.getWindowExpression(), aggregateAnalysis.getAggregateFunctionArguments(), aggregateAnalysis.getFunctionList(), aggregateAnalysis.getRequiredColumnsList(), aggregateAnalysis.getFinalSelectExpressions(), aggregateAnalysis.getHavingExpression());
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class AggregateNode method buildAggregateSchema.
private Schema buildAggregateSchema(final Schema schema, final FunctionRegistry functionRegistry) {
final SchemaBuilder schemaBuilder = SchemaBuilder.struct();
final List<Field> fields = schema.fields();
for (int i = 0; i < getRequiredColumnList().size(); i++) {
schemaBuilder.field(fields.get(i).name(), fields.get(i).schema());
}
for (int aggFunctionVarSuffix = 0; aggFunctionVarSuffix < getFunctionList().size(); aggFunctionVarSuffix++) {
String udafName = getFunctionList().get(aggFunctionVarSuffix).getName().getSuffix();
KsqlAggregateFunction aggregateFunction = functionRegistry.getAggregateFunction(udafName, getFunctionList().get(aggFunctionVarSuffix).getArguments(), schema);
schemaBuilder.field(AggregateExpressionRewriter.AGGREGATE_FUNCTION_VARIABLE_PREFIX + aggFunctionVarSuffix, aggregateFunction.getReturnType());
}
return schemaBuilder.build();
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class SerDeUtil method getSchemaFromAvro.
public static Schema getSchemaFromAvro(String avroSchemaString) {
org.apache.avro.Schema.Parser parser = new org.apache.avro.Schema.Parser();
org.apache.avro.Schema avroSchema = parser.parse(avroSchemaString);
SchemaBuilder inferredSchema = SchemaBuilder.struct().name(avroSchema.getName());
for (org.apache.avro.Schema.Field avroField : avroSchema.getFields()) {
inferredSchema.field(avroField.name(), getKsqlSchemaForAvroSchema(avroField.schema()));
}
return inferredSchema.build();
}
use of org.apache.kafka.connect.data.SchemaBuilder in project connect-utils by jcustenborder.
the class SchemaBuildersTest method excludeFields.
@Test
public void excludeFields() {
final Schema input = SchemaBuilder.struct().field("firstName", Schema.STRING_SCHEMA).field("lastName", Schema.STRING_SCHEMA).build();
final Schema expected = SchemaBuilder.struct().field("firstName", Schema.STRING_SCHEMA).build();
SchemaBuilder builder = SchemaBuilders.of(input, "lastName");
assertEquals(expected, builder.build());
}
Aggregations