Search in sources :

Example 1 with Header

use of io.confluent.ksql.rest.entity.StreamedRow.Header in project ksql by confluentinc.

the class Console method formatFieldType.

private static String formatFieldType(final FieldInfo field, final Optional<WindowType> windowType, final boolean isTable) {
    final FieldType possibleFieldType = field.getType().orElse(null);
    if (possibleFieldType == FieldType.HEADER) {
        final String headerType = field.getHeaderKey().map(k -> "(header('" + k + "'))").orElse("(headers)");
        return String.format("%-16s %s", field.getSchema().toTypeString(), headerType);
    }
    if (possibleFieldType == FieldType.KEY) {
        final String wt = windowType.map(v -> " (Window type: " + v + ")").orElse("");
        final String keyType = isTable ? "(primary key)" : "(key)";
        return String.format("%-16s %s%s", field.getSchema().toTypeString(), keyType, wt);
    }
    return field.getSchema().toTypeString();
}
Also used : Arrays(java.util.Arrays) Builder(io.confluent.ksql.cli.console.table.Table.Builder) StreamsList(io.confluent.ksql.rest.entity.StreamsList) PropertiesListTableBuilder(io.confluent.ksql.cli.console.table.builder.PropertiesListTableBuilder) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) OnOff(io.confluent.ksql.cli.console.CliConfig.OnOff) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) StringUtils(org.apache.commons.lang3.StringUtils) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) Map(java.util.Map) WindowType(io.confluent.ksql.model.WindowType) TablesListTableBuilder(io.confluent.ksql.cli.console.table.builder.TablesListTableBuilder) Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) TableBuilder(io.confluent.ksql.cli.console.table.builder.TableBuilder) TypeList(io.confluent.ksql.rest.entity.TypeList) ListVariablesTableBuilder(io.confluent.ksql.cli.console.table.builder.ListVariablesTableBuilder) StatusClosable(io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable) Handler1(io.confluent.ksql.util.HandlerMaps.Handler1) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo) ApiJsonMapper(io.confluent.ksql.rest.ApiJsonMapper) ZoneId(java.time.ZoneId) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Stream(java.util.stream.Stream) TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) KsqlException(io.confluent.ksql.util.KsqlException) TerminateQueryTableBuilder(io.confluent.ksql.cli.console.table.builder.TerminateQueryTableBuilder) DropConnectorEntity(io.confluent.ksql.rest.entity.DropConnectorEntity) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) TopicDescriptionTableBuilder(io.confluent.ksql.cli.console.table.builder.TopicDescriptionTableBuilder) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) Supplier(java.util.function.Supplier) CmdLineUtil.splitByUnquotedWhitespace(io.confluent.ksql.util.CmdLineUtil.splitByUnquotedWhitespace) DropConnectorTableBuilder(io.confluent.ksql.cli.console.table.builder.DropConnectorTableBuilder) StringTokenizer(java.util.StringTokenizer) TypeListTableBuilder(io.confluent.ksql.cli.console.table.builder.TypeListTableBuilder) CliSpecificCommand(io.confluent.ksql.cli.console.cmd.CliSpecificCommand) IOException(java.io.IOException) File(java.io.File) Paths(java.nio.file.Paths) Signal(org.jline.terminal.Terminal.Signal) HandlerMaps(io.confluent.ksql.util.HandlerMaps) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) LoggerFactory(org.slf4j.LoggerFactory) Header(io.confluent.ksql.rest.entity.StreamedRow.Header) WarningEntityTableBuilder(io.confluent.ksql.cli.console.table.builder.WarningEntityTableBuilder) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) KafkaTopicsListExtended(io.confluent.ksql.rest.entity.KafkaTopicsListExtended) DataRow(io.confluent.ksql.rest.entity.StreamedRow.DataRow) CommandStatusTableBuilder(io.confluent.ksql.cli.console.table.builder.CommandStatusTableBuilder) ExecutionPlan(io.confluent.ksql.rest.entity.ExecutionPlan) StreamsListTableBuilder(io.confluent.ksql.cli.console.table.builder.StreamsListTableBuilder) Table(io.confluent.ksql.cli.console.table.Table) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ClassHandlerMap1(io.confluent.ksql.util.HandlerMaps.ClassHandlerMap1) QueriesTableBuilder(io.confluent.ksql.cli.console.table.builder.QueriesTableBuilder) ErrorEntityTableBuilder(io.confluent.ksql.cli.console.table.builder.ErrorEntityTableBuilder) FieldType(io.confluent.ksql.rest.entity.FieldInfo.FieldType) Streams(com.google.common.collect.Streams) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) CreateConnectorEntity(io.confluent.ksql.rest.entity.CreateConnectorEntity) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) Entry(java.util.Map.Entry) ConnectorInfoTableBuilder(io.confluent.ksql.cli.console.table.builder.ConnectorInfoTableBuilder) Optional(java.util.Optional) ExecutionPlanTableBuilder(io.confluent.ksql.cli.console.table.builder.ExecutionPlanTableBuilder) WarningEntity(io.confluent.ksql.rest.entity.WarningEntity) HistoryEntry(io.confluent.ksql.cli.console.KsqlTerminal.HistoryEntry) TerminateQueryEntity(io.confluent.ksql.rest.entity.TerminateQueryEntity) ConnectorPluginsListTableBuilder(io.confluent.ksql.cli.console.table.builder.ConnectorPluginsListTableBuilder) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) QueryError(io.confluent.ksql.query.QueryError) SignalHandler(org.jline.terminal.Terminal.SignalHandler) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ImmutableList(com.google.common.collect.ImmutableList) Charset(java.nio.charset.Charset) ObjectUtils(org.apache.commons.lang3.ObjectUtils) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KafkaTopicsListTableBuilder(io.confluent.ksql.cli.console.table.builder.KafkaTopicsListTableBuilder) Queries(io.confluent.ksql.rest.entity.Queries) TablesList(io.confluent.ksql.rest.entity.TablesList) VariablesList(io.confluent.ksql.rest.entity.VariablesList) CmdLineUtil(io.confluent.ksql.util.CmdLineUtil) TabularRow(io.confluent.ksql.util.TabularRow) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Maps(com.google.common.collect.Maps) ConfigException(org.apache.kafka.common.config.ConfigException) ConnectorListTableBuilder(io.confluent.ksql.cli.console.table.builder.ConnectorListTableBuilder) FunctionNameListTableBuilder(io.confluent.ksql.cli.console.table.builder.FunctionNameListTableBuilder) Closeable(java.io.Closeable) DateTimeFormatter(java.time.format.DateTimeFormatter) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) Comparator(java.util.Comparator) Collections(java.util.Collections) FieldType(io.confluent.ksql.rest.entity.FieldInfo.FieldType)

Example 2 with Header

use of io.confluent.ksql.rest.entity.StreamedRow.Header in project ksql by confluentinc.

the class HARouting method streamedRowsHandler.

private static Consumer<List<StreamedRow>> streamedRowsHandler(final KsqlNode owner, final PullQueryQueue pullQueryQueue, final BiFunction<List<?>, LogicalSchema, PullQueryRow> rowFactory, final LogicalSchema outputSchema, final Optional<ConsistencyOffsetVector> consistencyOffsetVector) {
    final AtomicInteger processedRows = new AtomicInteger(0);
    final AtomicReference<Header> header = new AtomicReference<>();
    return streamedRows -> {
        try {
            if (streamedRows == null || streamedRows.isEmpty()) {
                return;
            }
            final List<PullQueryRow> rows = new ArrayList<>();
            // If this is the first row overall, skip the header
            final int previousProcessedRows = processedRows.getAndAdd(streamedRows.size());
            for (int i = 0; i < streamedRows.size(); i++) {
                final StreamedRow row = streamedRows.get(i);
                if (i == 0 && previousProcessedRows == 0) {
                    final Optional<Header> optionalHeader = row.getHeader();
                    optionalHeader.ifPresent(h -> validateSchema(outputSchema, h.getSchema(), owner));
                    optionalHeader.ifPresent(header::set);
                    continue;
                }
                if (row.getErrorMessage().isPresent()) {
                    // If we receive an error that's not a network error, we let that bubble up.
                    throw new KsqlException(row.getErrorMessage().get().getMessage());
                }
                if (!row.getRow().isPresent()) {
                    parseNonDataRows(row, i, consistencyOffsetVector);
                    continue;
                }
                final List<?> r = row.getRow().get().getColumns();
                Preconditions.checkNotNull(header.get());
                rows.add(rowFactory.apply(r, header.get().getSchema()));
            }
            if (!pullQueryQueue.acceptRows(rows)) {
                LOG.error("Failed to queue all rows");
            }
        } catch (Exception e) {
            throw new KsqlException(e.getMessage(), e);
        }
    };
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Query(io.confluent.ksql.parser.tree.Query) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) MaterializationException(io.confluent.ksql.execution.streams.materialization.MaterializationException) RoutingFilterFactory(io.confluent.ksql.execution.streams.RoutingFilter.RoutingFilterFactory) BiFunction(java.util.function.BiFunction) ServiceContext(io.confluent.ksql.services.ServiceContext) LoggerFactory(org.slf4j.LoggerFactory) RoutingOptions(io.confluent.ksql.execution.streams.RoutingOptions) KsqlNode(io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode) Header(io.confluent.ksql.rest.entity.StreamedRow.Header) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RestResponse(io.confluent.ksql.rest.client.RestResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ImmutableList(com.google.common.collect.ImmutableList) NotUpToBoundException(io.confluent.ksql.execution.streams.materialization.ks.NotUpToBoundException) Host(io.confluent.ksql.execution.streams.RoutingFilter.Host) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) QueryId(io.confluent.ksql.query.QueryId) ExecutorService(java.util.concurrent.ExecutorService) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlConfig(io.confluent.ksql.util.KsqlConfig) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) PullQueryExecutorMetrics(io.confluent.ksql.internal.PullQueryExecutorMetrics) ConsistencyOffsetVector(io.confluent.ksql.util.ConsistencyOffsetVector) Entry(java.util.Map.Entry) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) PullPhysicalPlanType(io.confluent.ksql.physical.pull.PullPhysicalPlan.PullPhysicalPlanType) PullQueryQueue(io.confluent.ksql.query.PullQueryQueue) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) Header(io.confluent.ksql.rest.entity.StreamedRow.Header) Optional(java.util.Optional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) KsqlException(io.confluent.ksql.util.KsqlException) MaterializationException(io.confluent.ksql.execution.streams.materialization.MaterializationException) NotUpToBoundException(io.confluent.ksql.execution.streams.materialization.ks.NotUpToBoundException) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)2 Header (io.confluent.ksql.rest.entity.StreamedRow.Header)2 KsqlException (io.confluent.ksql.util.KsqlException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Maps (com.google.common.collect.Maps)1 Streams (com.google.common.collect.Streams)1