-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(static): initial drop of static query functionality (#3340)
* feat(static): initial drop of static query functionality The change brings in the first batch of functionality for static query. It allows static queries on both windowed and non-windowed aggregate tables, i.e. tables build with a `GROUP BY` clause. For non-windowed queries the following form is accepted: ``` SELECT * FROM X WHERE ROWKEY=Y; ``` - The only filter allowed is an equals filter on ROWKEY. - Only a single ROWKEY is supported at the moment. - Only `SELECT *` is supported at the moment. For windowed queries the following forms is accepted: ``` -- exact window start: SELECT * FROM X WHERE ROWKEY=Y AND WINDOWSTART=X; SELECT * FROM X WHERE ROWKEY=Y AND WINDOWSTART='2020-02-23T23:45:12.000'; -- windwo start range: SELECT * FROM X WHERE ROWKEY=Y AND WINDOWSTART>A AND WINDOWSTART<=B; SELECT * FROM X WHERE ROWKEY=Y AND '2020-02-23T23:45:12.000' < WINDOWSTART AND WINDOWSTART <= '2020-02-24T23:45:12.000'; ``` All types of windowed tables are supported. At the moment, static query requests are served over the standard `/ksql` HTTP POST request. But this may change to being a websocket request. * chore: fix test * chore: reviewer's requested changes
- Loading branch information
1 parent
6747d5c
commit 54c5139
Showing
64 changed files
with
6,844 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...li/src/main/java/io/confluent/ksql/cli/console/table/builder/QueryResultTableBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.cli.console.table.builder; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import io.confluent.ksql.cli.console.table.Table; | ||
import io.confluent.ksql.cli.console.table.Table.Builder; | ||
import io.confluent.ksql.model.WindowType; | ||
import io.confluent.ksql.rest.entity.QueryResultEntity; | ||
import io.confluent.ksql.rest.entity.QueryResultEntity.Row; | ||
import io.confluent.ksql.schema.ksql.Column; | ||
import io.confluent.ksql.schema.ksql.LogicalSchema; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class QueryResultTableBuilder implements TableBuilder<QueryResultEntity> { | ||
|
||
private static final List<String> TIME_WINDOW_HEADINGS = ImmutableList | ||
.of("WINDOWSTART BIGINT"); | ||
|
||
private static final List<String> SESSION_WINDOW_HEADINGS = ImmutableList.<String>builder() | ||
.addAll(TIME_WINDOW_HEADINGS) | ||
.add("WINDOWEND BIGINT") | ||
.build(); | ||
|
||
@Override | ||
public Table buildTable(final QueryResultEntity entity) { | ||
|
||
final List<String> headers = buildHeadings(entity); | ||
|
||
final Stream<List<String>> rows = entity | ||
.getRows() | ||
.stream() | ||
.map(r -> buildRow(r, entity.getSchema().value())); | ||
|
||
return new Builder() | ||
.withColumnHeaders(headers) | ||
.withRows(rows) | ||
.build(); | ||
} | ||
|
||
private static List<String> buildHeadings(final QueryResultEntity entity) { | ||
final LogicalSchema schema = entity.getSchema(); | ||
|
||
final Stream<String> keys = schema.key().stream() | ||
.map(f -> f.fullName() + " " + f.type() + " KEY"); | ||
|
||
final Stream<String> window = entity.getWindowType() | ||
.map(wt -> wt == WindowType.SESSION | ||
? SESSION_WINDOW_HEADINGS | ||
: TIME_WINDOW_HEADINGS) | ||
.orElse(ImmutableList.of()) | ||
.stream(); | ||
|
||
final Stream<String> values = schema.value().stream() | ||
.map(f -> f.fullName() + " " + f.type()); | ||
|
||
return Stream.concat(keys, Stream.concat(window, values)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static List<String> buildRow( | ||
final Row row, | ||
final List<Column> valueSchema | ||
) { | ||
final Stream<?> keys = row.getKey().values().stream(); | ||
|
||
final Stream<?> window = row.getWindow() | ||
.map(w -> w.getEnd().isPresent() | ||
? Stream.of(w.getStart(), w.getEnd().getAsLong()) | ||
: Stream.of(w.getStart())) | ||
.orElse(Stream.of()); | ||
|
||
final Stream<?> values = row.getValue() == null | ||
? valueSchema.stream().map(f -> null) | ||
: row.getValue().values().stream(); | ||
|
||
return Stream.concat(keys, Stream.concat(window, values)) | ||
.map(Objects::toString) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.