Search in sources :

Example 1 with ColumnConstraints

use of io.confluent.ksql.parser.tree.ColumnConstraints in project ksql by confluentinc.

the class DefaultSchemaInjector method buildElements.

private static TableElements buildElements(final ConfiguredStatement<CreateSource> preparedStatement, final Optional<SchemaAndId> keySchema, final Optional<SchemaAndId> valueSchema) {
    final List<TableElement> elements = new ArrayList<>();
    if (keySchema.isPresent()) {
        final ColumnConstraints constraints = getKeyConstraints(preparedStatement.getStatement());
        keySchema.get().columns.stream().map(col -> new TableElement(col.name(), new Type(col.type()), constraints)).forEach(elements::add);
    } else {
        getKeyColumns(preparedStatement).forEach(elements::add);
    }
    if (valueSchema.isPresent()) {
        valueSchema.get().columns.stream().map(col -> new TableElement(col.name(), new Type(col.type()))).forEach(elements::add);
    } else {
        getValueColumns(preparedStatement).forEach(elements::add);
    }
    return TableElements.of(elements);
}
Also used : IntStream(java.util.stream.IntStream) FormatFactory(io.confluent.ksql.serde.FormatFactory) ServiceContext(io.confluent.ksql.services.ServiceContext) SerdeFeaturesFactory(io.confluent.ksql.serde.SerdeFeaturesFactory) CommonCreateConfigs(io.confluent.ksql.properties.with.CommonCreateConfigs) TableElement(io.confluent.ksql.parser.tree.TableElement) ArrayList(java.util.ArrayList) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Injector(io.confluent.ksql.statement.Injector) CreateTable(io.confluent.ksql.parser.tree.CreateTable) CreateSource(io.confluent.ksql.parser.tree.CreateSource) SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) ColumnConstraints(io.confluent.ksql.parser.tree.ColumnConstraints) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) CreateSourceAsProperties(io.confluent.ksql.parser.properties.with.CreateSourceAsProperties) SchemaAndId(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId) CreateSourceCommand(io.confluent.ksql.execution.ddl.commands.CreateSourceCommand) ImmutableSet(com.google.common.collect.ImmutableSet) Type(io.confluent.ksql.execution.expression.tree.Type) ImmutableMap(com.google.common.collect.ImmutableMap) SerdeFeature(io.confluent.ksql.serde.SerdeFeature) SetView(com.google.common.collect.Sets.SetView) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) SqlFormatter(io.confluent.ksql.parser.SqlFormatter) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) SourcePropertiesUtil(io.confluent.ksql.parser.properties.with.SourcePropertiesUtil) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ErrorMessageUtil(io.confluent.ksql.util.ErrorMessageUtil) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Objects(java.util.Objects) CreateAsSelect(io.confluent.ksql.parser.tree.CreateAsSelect) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties) List(java.util.List) Stream(java.util.stream.Stream) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Format(io.confluent.ksql.serde.Format) TableElements(io.confluent.ksql.parser.tree.TableElements) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Statement(io.confluent.ksql.parser.tree.Statement) Column(io.confluent.ksql.schema.ksql.Column) FormatInfo(io.confluent.ksql.serde.FormatInfo) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) Type(io.confluent.ksql.execution.expression.tree.Type) ColumnConstraints(io.confluent.ksql.parser.tree.ColumnConstraints) ArrayList(java.util.ArrayList) TableElement(io.confluent.ksql.parser.tree.TableElement)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 SetView (com.google.common.collect.Sets.SetView)1 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 CreateSourceCommand (io.confluent.ksql.execution.ddl.commands.CreateSourceCommand)1 Type (io.confluent.ksql.execution.expression.tree.Type)1 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)1 SqlFormatter (io.confluent.ksql.parser.SqlFormatter)1 CreateSourceAsProperties (io.confluent.ksql.parser.properties.with.CreateSourceAsProperties)1 CreateSourceProperties (io.confluent.ksql.parser.properties.with.CreateSourceProperties)1 SourcePropertiesUtil (io.confluent.ksql.parser.properties.with.SourcePropertiesUtil)1 ColumnConstraints (io.confluent.ksql.parser.tree.ColumnConstraints)1 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)1 CreateSource (io.confluent.ksql.parser.tree.CreateSource)1 CreateStream (io.confluent.ksql.parser.tree.CreateStream)1 CreateTable (io.confluent.ksql.parser.tree.CreateTable)1 Statement (io.confluent.ksql.parser.tree.Statement)1 TableElement (io.confluent.ksql.parser.tree.TableElement)1 TableElements (io.confluent.ksql.parser.tree.TableElements)1