Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[To dev/1.3] Fix back-quote remove of Select-Into query when query is not for raw data #14274

Merged
merged 2 commits into from
Dec 3, 2024
Merged
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 @@ -785,4 +785,53 @@ public void testNewDataType() {
String expectedQueryHeader = "Time,root.db.d2.s7,root.db.d2.s8,root.db.d2.s9,root.db.d2.s10,";
resultSetEqualTest("select s7,s8,s9,s10 from root.db.d2;", expectedQueryHeader, resultSet);
}

// -------------------------------------- OTHER TEST -------------------------------------
@Test
public void testRemoveBackQuote() {
String[] intoRetArray =
new String[] {
"count(root.sg.d1.s1),root.sg_agg1.d1.count_s1,1,",
"last_value(root.sg.d1.s2),root.sg_agg1.d1.last_value_s2,1,",
"count(root.sg.d2.s1),root.sg_agg1.d2.count_s1,1,",
"last_value(root.sg.d2.s2),root.sg_agg1.d2.last_value_s2,1,"
};
resultSetEqualTest(
"select count(d1.s1), last_value(d1.s2), count(d2.s1), last_value(d2.s2) "
+ "into root.sg_agg1.`d1`(`count_s1`, last_value_s2), aligned root.sg_agg1.d2(count_s1, last_value_s2) "
+ "from root.sg;",
selectIntoHeader,
intoRetArray);

String expectedQueryHeader =
"Time,root.sg_agg1.d1.count_s1,root.sg_agg1.d2.count_s1,root.sg_agg1.d1.last_value_s2,root.sg_agg1.d2.last_value_s2,";
String[] queryRetArray = new String[] {"0,10,7,12.0,11.0,"};
resultSetEqualTest(
"select count_s1, last_value_s2 from root.sg_agg1.d1, root.sg_agg1.d2;",
expectedQueryHeader,
queryRetArray);
}

@Test
public void testRemoveBackQuoteAlignByDevice() {
String[] intoRetArray =
new String[] {
"root.sg.d1,count(s1),root.sg_abd_agg1.d1.count_s1,1,",
"root.sg.d1,last_value(s2),root.sg_abd_agg1.d1.last_value_s2,1,"
};
resultSetEqualTest(
"select count(s1), last_value(s2) "
+ "into root.sg_abd_agg1.`d1`(`count_s1`, last_value_s2) "
+ "from root.sg.d1 align by device;",
selectIntoAlignByDeviceHeader,
intoRetArray);

String expectedQueryHeader =
"Time,root.sg_abd_agg1.d1.count_s1," + "root.sg_abd_agg1.d1.last_value_s2,";
String[] queryRetArray = new String[] {"0,10,12.0,"};
resultSetEqualTest(
"select count_s1, last_value_s2 from root.sg_abd_agg1.d1, root.sg_abd_agg1.d2;",
expectedQueryHeader,
queryRetArray);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@
import static org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetDevice;
import static org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetMeasurement;
import static org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetPath;
import static org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetPathWithoutPlaceHolder;
import static org.apache.iotdb.db.queryengine.plan.optimization.LimitOffsetPushDown.canPushDownLimitOffsetInGroupByTimeForDevice;
import static org.apache.iotdb.db.queryengine.plan.optimization.LimitOffsetPushDown.pushDownLimitOffsetInGroupByTimeForDevice;
import static org.apache.iotdb.db.queryengine.plan.parser.ASTVisitor.parseNodeString;
import static org.apache.iotdb.db.schemaengine.schemaregion.view.visitor.GetSourcePathsVisitor.getSourcePaths;
import static org.apache.iotdb.db.storageengine.load.metrics.LoadTsFileCostMetricsSet.ANALYSIS;
import static org.apache.iotdb.db.utils.constant.SqlConstant.COUNT_TIME_HEADER;
Expand Down Expand Up @@ -2343,7 +2345,7 @@ private void analyzeInto(
constructTargetMeasurement(
sourceDevice.concatNode(sourceColumn.getExpressionString()), measurementTemplate);
} else {
targetMeasurement = measurementTemplate;
targetMeasurement = parseNodeString(measurementTemplate);
}
deviceViewIntoPathDescriptor.specifyTargetDeviceMeasurement(
sourceDevice, targetDevice, sourceColumn.getExpressionString(), targetMeasurement);
Expand Down Expand Up @@ -2414,7 +2416,7 @@ private void analyzeInto(
}
targetPath = constructTargetPath(sourcePath, deviceTemplate, measurementTemplate);
} else {
targetPath = deviceTemplate.concatNode(measurementTemplate);
targetPath = constructTargetPathWithoutPlaceHolder(deviceTemplate, measurementTemplate);
}
intoPathDescriptor.specifyTargetPath(sourceColumn, viewPath, targetPath);
intoPathDescriptor.specifyDeviceAlignment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.iotdb.db.queryengine.common.schematree.ISchemaTree;
import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
import org.apache.iotdb.db.queryengine.plan.parser.ASTVisitor;
import org.apache.iotdb.db.utils.TypeInferenceUtils;

import org.apache.tsfile.enums.TSDataType;
Expand All @@ -41,13 +40,26 @@
import static com.google.common.base.Preconditions.checkState;
import static org.apache.iotdb.commons.conf.IoTDBConstant.DOUBLE_COLONS;
import static org.apache.iotdb.commons.conf.IoTDBConstant.LEVELED_PATH_TEMPLATE_PATTERN;
import static org.apache.iotdb.db.queryengine.plan.parser.ASTVisitor.parseNodeString;

public class SelectIntoUtils {

private SelectIntoUtils() {
// forbidding instantiation
}

public static PartialPath constructTargetPathWithoutPlaceHolder(
PartialPath devicePath, String measurement) {
String[] originalDeviceNodes = devicePath.getNodes();
String[] resNodes = new String[originalDeviceNodes.length + 1];

for (int i = 0; i < originalDeviceNodes.length; i++) {
resNodes[i] = parseNodeString(originalDeviceNodes[i]);
}
resNodes[resNodes.length - 1] = parseNodeString(measurement);
return new MeasurementPath(resNodes);
}

public static PartialPath constructTargetPath(
PartialPath sourcePath, PartialPath deviceTemplate, String measurementTemplate) {
PartialPath targetDevice = constructTargetDevice(sourcePath.getDevicePath(), deviceTemplate);
Expand Down Expand Up @@ -108,7 +120,7 @@ private static String applyLevelPlaceholder(String templateNode, String[] source
resNode = matcher.replaceFirst(sourceNodes[index]);
matcher = LEVELED_PATH_TEMPLATE_PATTERN.matcher(resNode);
}
return ASTVisitor.parseNodeString(resNode);
return parseNodeString(resNode);
}

public static boolean checkIsAllRawSeriesQuery(List<Expression> expressions) {
Expand Down
Loading