Skip to content

Commit

Permalink
fix: disable creation of stream table with columns with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
yukkit committed Nov 15, 2023
1 parent 69199e0 commit 4885567
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions query_server/query/src/data_source/stream/tskv/factory.rs
@@ -1,3 +1,4 @@
use std::collections::HashSet;
use std::sync::Arc;

use coordinator::service::CoordinatorRef;
Expand Down Expand Up @@ -65,9 +66,16 @@ impl SchemaChecker<StreamTable> for TskvStreamProviderFactory {
})?;

// Make sure that the columns specified in [`StreamTable`] must be included in the target table
let mut duplicated_cols = HashSet::new();
let target_schema = target_table.to_arrow_schema();
for f in table.schema().fields() {
target_schema.field_with_name(f.name())?;
// check same col name
if !duplicated_cols.insert(f.name()) {
return Err(QueryError::SameColumnName {
column: f.name().to_string(),
});
}
}

// check 'event_time_column'
Expand Down
14 changes: 14 additions & 0 deletions query_server/sqllogicaltests/cases/stream/syntax.slt
Expand Up @@ -86,6 +86,20 @@ CREATE STREAM TABLE TskvTable (
event_time_column = 'time'
) engine = xxx;

# same col name
statement error Arrow error: Io error: Status \{ code: Internal, message: "Execute logical plan: Semantic error: Field or Tag have the same name time", .*
CREATE STREAM TABLE TskvTable (
time TIMESTAMP,
time TIMESTAMP,
name STRING,
driver STRING,
elevation DOUBLE
) WITH (
db = 'public',
table = 'readings_kv',
event_time_column = 'time'
) engine = tskv;

# event_time_column does not match
statement error .*Schema error: Unable to get field named \\"timex\\"\. Valid fields: \[\\"time\\", \\"name\\", \\"fleet\\", \\"driver\\", \\"model\\", \\"device_version\\", \\"latitude\\", \\"longitude\\", \\"elevation\\", \\"velocity\\", \\"heading\\", \\"grade\\", \\"fuel_consumption\\", \\"load_capacity\\", \\"fuel_capacity\\", \\"nominal_fuel_consumption\\"\]", .*
CREATE STREAM TABLE TskvTable (
Expand Down

0 comments on commit 4885567

Please sign in to comment.