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 @@ -267,11 +267,16 @@ public void insertWrongTimeSqlTest()
"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')");
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());
assertFalse(dataSet.hasNext());
}
try {
session.executeNonQueryStatement("insert into wrong_time values(1.0,'bb','cc','dd')");
Expand Down Expand Up @@ -333,6 +338,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 +356,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 @@ -165,17 +165,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 @@ -195,6 +195,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 @@ -178,6 +178,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 @@ -791,6 +792,11 @@ public Scope visitInsertRows(InsertRows node, Optional<Scope> context) {
}

private Scope visitInsert(WrappedInsertStatement insert, Optional<Scope> scope) {
if (insert instanceof InsertValues) {
((InsertValues) insert)
.materialize(new PlannerContext(metadata, typeManager), sessionContext);
}

final Scope ret = Scope.create();

final MPPQueryContext context = insert.getContext();
Expand Down
Loading