Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,36 @@ public void insertWrongTimeSqlTest()
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
session.executeNonQueryStatement("USE \"db1\"");
session.executeNonQueryStatement(
"create table wrong_time(color string tag, device_id string tag,city string attribute)");
"create table wrong_time(color string tag, device_id string tag,city string attribute,"
+ " value int32 field)");
try {
session.executeNonQueryStatement("insert into wrong_time values('aa','bb','cc','dd')");
session.executeNonQueryStatement("insert into wrong_time values('aa','bb','cc','dd',1)");
fail("No exception thrown");
} catch (StatementExecutionException e) {
assertEquals(
"701: Input time format aa error. Input like yyyy-MM-dd HH:mm:ss, yyyy-MM-ddTHH:mm:ss or refer to user document for more info.",
e.getMessage());
}
try {
session.executeNonQueryStatement("insert into wrong_time values(1+1,'bb','cc','dd')");
fail("No exception thrown");
} catch (StatementExecutionException e) {
assertEquals("701: Unsupported expression: (1 + 1)", e.getMessage());
session.executeNonQueryStatement("insert into wrong_time values(1+1,'bb','cc','dd',1)");
try (SessionDataSet dataSet =
session.executeQueryStatement("select * from wrong_time where time = 2")) {
assertTrue(dataSet.hasNext());
RowRecord rowRecord = dataSet.next();
assertEquals(2L, rowRecord.getFields().get(0).getLongV());
assertEquals("bb", rowRecord.getFields().get(1).getBinaryV().toString());
assertEquals("cc", rowRecord.getFields().get(2).getBinaryV().toString());
assertEquals("dd", rowRecord.getFields().get(3).getBinaryV().toString());
assertEquals(1, rowRecord.getFields().get(4).getIntV());
assertFalse(dataSet.hasNext());
}
try {
session.executeNonQueryStatement("insert into wrong_time values(1.0,'bb','cc','dd')");
session.executeNonQueryStatement("insert into wrong_time values(1.0,'bb','cc','dd',1)");
fail("No exception thrown");
} catch (StatementExecutionException e) {
assertEquals("701: Unsupported expression: 1E0", e.getMessage());
}
try {
session.executeNonQueryStatement("insert into wrong_time values(true,'bb','cc','dd')");
session.executeNonQueryStatement("insert into wrong_time values(true,'bb','cc','dd',1)");
fail("No exception thrown");
} catch (StatementExecutionException e) {
assertEquals("701: Unsupported expression: true", e.getMessage());
Expand Down Expand Up @@ -333,6 +340,14 @@ public void insertRelationalSqlTest()
row, "tag:" + row, "attr:" + row, row));
}

session.executeNonQueryStatement(
"INSERT INTO table1 (time, tag1, attr1, m1) "
+ "VALUES (if(true, 50, 0), if(true, 'tag:50', 'x'), "
+ "if(false, 'x', 'attr:50'), if(true, 50.0, 0.0))");
session.executeNonQueryStatement(
"INSERT INTO table1 VALUES (if(true, 51, 0), if(true, 'tag:51', 'x'), "
+ "if(true, 'attr:51', 'x'), if(false, 0, 51))");

SessionDataSet dataSet = session.executeQueryStatement("select * from table1 order by time");
int cnt = 0;
while (dataSet.hasNext()) {
Expand All @@ -343,7 +358,7 @@ public void insertRelationalSqlTest()
assertEquals(timestamp * 1.0, rowRecord.getFields().get(3).getDoubleV(), 0.0001);
cnt++;
}
assertEquals(50, cnt);
assertEquals(52, cnt);

// sql cannot create column
assertThrows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ public List<WritePlanNode> splitByPartition(IAnalysis analysis) {
List<WritePlanNode> writePlanNodeList = new ArrayList<>();
Map<TRegionReplicaSet, RelationalInsertRowsNode> splitMap = new HashMap<>();
List<TEndPoint> redirectInfo = new ArrayList<>();
String databaseName = getDatabaseName(analysis);
for (int i = 0; i < getInsertRowNodeList().size(); i++) {
InsertRowNode insertRowNode = getInsertRowNodeList().get(i);
// Data region for insert row node
// each row may belong to different database, pass null for auto-detection
TRegionReplicaSet dataRegionReplicaSet =
analysis
.getDataPartitionInfo()
.getDataRegionReplicaSetForWriting(
insertRowNode.getDeviceID(),
TimePartitionUtils.getTimePartitionSlot(insertRowNode.getTime()),
analysis.getDatabaseName());
databaseName);

// Collect redirectInfo
redirectInfo.add(dataRegionReplicaSet.getDataNodeLocations().get(0).getClientRpcEndPoint());
Expand All @@ -231,6 +231,14 @@ public List<WritePlanNode> splitByPartition(IAnalysis analysis) {
return writePlanNodeList;
}

private String getDatabaseName(IAnalysis analysis) {
if (analysis.getDataPartitionInfo() != null
&& analysis.getDataPartitionInfo().getDataPartitionMap().size() == 1) {
return analysis.getDataPartitionInfo().getDataPartitionMap().keySet().iterator().next();
}
return analysis.getDatabaseName();
}

public RelationalInsertRowsNode emptyClone() {
return new RelationalInsertRowsNode(this.getPlanNodeId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.InsertRow;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.InsertRows;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.InsertTablet;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.InsertValues;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.LoadTsFile;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.PipeEnriched;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Property;
Expand Down Expand Up @@ -856,6 +857,11 @@
}

private Scope visitInsert(WrappedInsertStatement insert, Optional<Scope> scope) {
if (insert instanceof InsertValues) {

Check warning on line 860 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this instanceof check and cast with 'instanceof InsertValues insertvalues'

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ70Tu9y8hSCovrgAcgd&open=AZ70Tu9y8hSCovrgAcgd&pullRequest=17850
((InsertValues) insert)
.materialize(new PlannerContext(metadata, typeManager), sessionContext);
}

final Scope ret = Scope.create();

final MPPQueryContext context = insert.getContext();
Expand Down Expand Up @@ -2760,7 +2766,7 @@
}
}

private Analysis.GroupingSetAnalysis analyzeGroupBy(

Check warning on line 2769 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 131 to 64, Complexity from 24 to 14, Nesting Level from 6 to 2, Number of Variables from 28 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ6WiCa796qf42bbbA62&open=AZ6WiCa796qf42bbbA62&pullRequest=17850
QuerySpecification node,
Scope scope,
List<Expression> outputExpressions,
Expand Down Expand Up @@ -3216,7 +3222,7 @@
}

@Override
public Scope visitSetOperation(SetOperation node, Optional<Scope> scope) {

Check warning on line 3225 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 82 to 64, Complexity from 16 to 14, Nesting Level from 3 to 2, Number of Variables from 25 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ6WiCa796qf42bbbA63&open=AZ6WiCa796qf42bbbA63&pullRequest=17850
checkState(node.getRelations().size() >= 2);

List<RelationType> childrenTypes =
Expand Down Expand Up @@ -3507,7 +3513,7 @@
// accessControlScope, filter));
// }

public Scope visitPatternRecognitionRelation(

Check warning on line 3516 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 121 to 64, Complexity from 18 to 14, Nesting Level from 3 to 2, Number of Variables from 35 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ6WiCa796qf42bbbA64&open=AZ6WiCa796qf42bbbA64&pullRequest=17850
PatternRecognitionRelation relation, Optional<Scope> scope) {
Scope inputScope = process(relation.getInput(), scope);

Expand Down Expand Up @@ -3866,7 +3872,7 @@
}

@Override
public Scope visitJoin(Join node, Optional<Scope> scope) {

Check warning on line 3875 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 81 to 64, Complexity from 15 to 14, Nesting Level from 3 to 2, Number of Variables from 18 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ6WiCa796qf42bbbA65&open=AZ6WiCa796qf42bbbA65&pullRequest=17850
JoinCriteria criteria = node.getCriteria().orElse(null);

joinConditionCheck(criteria);
Expand Down Expand Up @@ -5199,7 +5205,7 @@
return null;
}

private ArgumentsAnalysis analyzeArguments(

Check warning on line 5208 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 81 to 64, Complexity from 15 to 14, Nesting Level from 3 to 2, Number of Variables from 25 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ6WiCa796qf42bbbA66&open=AZ6WiCa796qf42bbbA66&pullRequest=17850
List<ParameterSpecification> parameterSpecifications,
List<TableFunctionArgument> arguments,
Optional<Scope> scope,
Expand Down
Loading
Loading