Skip to content
Open
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 @@ -1634,7 +1634,8 @@
queryStatement.setOrderByComponent(
parseOrderByClause(
ctx.orderByClause(),
ImmutableSet.of(OrderByKey.TIME, OrderByKey.DEVICE, OrderByKey.TIMESERIES)));
ImmutableSet.of(OrderByKey.TIME, OrderByKey.DEVICE, OrderByKey.TIMESERIES),
true));
}

// parse FILL
Expand Down Expand Up @@ -1937,7 +1938,9 @@
// ---- Order By Clause
// all SortKeys should be contained by limitSet
private OrderByComponent parseOrderByClause(
IoTDBSqlParser.OrderByClauseContext ctx, ImmutableSet<String> limitSet) {
IoTDBSqlParser.OrderByClauseContext ctx,
ImmutableSet<String> limitSet,
boolean allowExpression) {
OrderByComponent orderByComponent = new OrderByComponent();
Set<String> sortKeySet = new HashSet<>();
for (IoTDBSqlParser.OrderByAttributeClauseContext orderByAttributeClauseContext :
Expand All @@ -1946,7 +1949,8 @@
if (orderByComponent.isUnique()) {
break;
}
SortItem sortItem = parseOrderByAttributeClause(orderByAttributeClauseContext, limitSet);
SortItem sortItem =
parseOrderByAttributeClause(orderByAttributeClauseContext, limitSet, allowExpression);

String sortKey = sortItem.getSortKey();
if (sortKeySet.contains(sortKey)) {
Expand All @@ -1965,7 +1969,9 @@
}

private SortItem parseOrderByAttributeClause(
IoTDBSqlParser.OrderByAttributeClauseContext ctx, ImmutableSet<String> limitSet) {
IoTDBSqlParser.OrderByAttributeClauseContext ctx,
ImmutableSet<String> limitSet,
boolean allowExpression) {
if (ctx.sortKey() != null) {
String sortKey = ctx.sortKey().getText().toUpperCase();
if (!limitSet.contains(sortKey)) {
Expand All @@ -1974,6 +1980,11 @@
}
return new SortItem(sortKey, ctx.DESC() != null ? Ordering.DESC : Ordering.ASC);
} else {
if (!allowExpression) {
throw new SemanticException(
"ORDER BY expression is not supported for current statement, supported sort key: "
+ limitSet.toString());
}
Expression sortExpression = parseExpression(ctx.expression(), true);
return new SortItem(
sortExpression,
Expand Down Expand Up @@ -3719,7 +3730,8 @@
OrderByKey.QUERYID,
OrderByKey.DATANODEID,
OrderByKey.ELAPSEDTIME,
OrderByKey.STATEMENT)));
OrderByKey.STATEMENT),
false));
}

// parse LIMIT & OFFSET
Expand Down Expand Up @@ -4550,7 +4562,7 @@
}

@Override
public Statement visitSetThrottleQuota(IoTDBSqlParser.SetThrottleQuotaContext ctx) {

Check warning on line 4565 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.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 95 to 64, Complexity from 20 to 14, Nesting Level from 3 to 2, Number of Variables from 14 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZrjfJ75wSXZKUwYz1wq&open=AZrjfJ75wSXZKUwYz1wq&pullRequest=16855
if (!IoTDBDescriptor.getInstance().getConfig().isQuotaEnable()) {
throw new SemanticException(LIMIT_CONFIGURATION_ENABLED_ERROR_MSG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,12 @@ private PlanNode processOneChildNode(PlanNode node, NodeGroupContext context) {
PlanNode newNode = node.clone();
PlanNode child = visit(node.getChildren().get(0), context);
newNode.addChild(child);
TRegionReplicaSet dataRegion = context.getNodeDistribution(child.getPlanNodeId()).getRegion();
NodeDistribution nodeDistribution = context.getNodeDistribution(child.getPlanNodeId());
context.putNodeDistribution(
newNode.getPlanNodeId(),
new NodeDistribution(NodeDistributionType.SAME_WITH_ALL_CHILDREN, dataRegion));
new NodeDistribution(
NodeDistributionType.SAME_WITH_ALL_CHILDREN,
nodeDistribution == null ? null : nodeDistribution.getRegion()));
return newNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ protected void serializeAttributes(DataOutputStream stream) throws IOException {
}

public static ShowQueriesNode deserialize(ByteBuffer byteBuffer) {
PlanNodeId planNodeId = PlanNodeId.deserialize(byteBuffer);
String allowedUsername = ReadWriteIOUtils.readString(byteBuffer);
PlanNodeId planNodeId = PlanNodeId.deserialize(byteBuffer);
return new ShowQueriesNode(planNodeId, null, allowedUsername);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public void addSortItem(SortItem sortItem) {
orderByDevice = true;
deviceOrderPriority = sortItemList.size() - 1;
break;
case OrderByKey.QUERYID:
case OrderByKey.DATANODEID:
case OrderByKey.ELAPSEDTIME:
case OrderByKey.STATEMENT:
// show queries statement
break;
default:
throw new IllegalArgumentException(
String.format("Unknown sort key %s", sortItem.getSortKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private void renderOperator(
addLineWithValueCheck(
singleFragmentInstanceArea,
indentNum + 2,
"Estimated Memory Size: ",
"Estimated Memory Size",
operatorStatistic.getMemoryUsage());

if (operatorStatistic.getSpecifiedInfoSize() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
import org.apache.iotdb.db.queryengine.plan.statement.Statement;
import org.apache.iotdb.db.queryengine.plan.statement.StatementTestUtils;
import org.apache.iotdb.db.queryengine.plan.statement.StatementType;
import org.apache.iotdb.db.queryengine.plan.statement.component.OrderByKey;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.queryengine.plan.statement.component.ResultColumn;
import org.apache.iotdb.db.queryengine.plan.statement.component.SortItem;
import org.apache.iotdb.db.queryengine.plan.statement.crud.DeleteDataStatement;
import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertMultiTabletsStatement;
import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowStatement;
Expand All @@ -60,6 +63,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.metadata.template.UnsetSchemaTemplateStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.view.CreateLogicalViewStatement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.AuthorStatement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.ShowQueriesStatement;
import org.apache.iotdb.isession.template.TemplateNode;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.service.rpc.thrift.TSAggregationQueryReq;
Expand Down Expand Up @@ -116,6 +120,35 @@

public class StatementGeneratorTest {

@Test
public void testShowQueries() {
Statement showQueries =
StatementGenerator.createStatement(
"show queries order by time, queryid, datanodeid, elapsedtime, statement",
ZonedDateTime.now().getOffset());
Assert.assertTrue(showQueries instanceof ShowQueriesStatement);
Assert.assertEquals(
((ShowQueriesStatement) showQueries).getSortItemList().get(0),
new SortItem(OrderByKey.TIME, Ordering.ASC));
Assert.assertEquals(
((ShowQueriesStatement) showQueries).getSortItemList().get(1),
new SortItem(OrderByKey.QUERYID, Ordering.ASC));
Assert.assertEquals(
((ShowQueriesStatement) showQueries).getSortItemList().get(2),
new SortItem(OrderByKey.DATANODEID, Ordering.ASC));
Assert.assertEquals(
((ShowQueriesStatement) showQueries).getSortItemList().get(3),
new SortItem(OrderByKey.ELAPSEDTIME, Ordering.ASC));
Assert.assertEquals(
((ShowQueriesStatement) showQueries).getSortItemList().get(4),
new SortItem(OrderByKey.STATEMENT, Ordering.ASC));
Assert.assertThrows(
SemanticException.class,
() ->
StatementGenerator.createStatement(
"show queries order by a", ZonedDateTime.now().getOffset()));
}

@Test
public void testRawDataQuery() throws IllegalPathException {
TSRawDataQueryReq req =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.iotdb.db.queryengine.plan.planner.node.PlanNodeDeserializeHelper;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.LastQueryScanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.ShowQueriesNode;

import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.write.schema.MeasurementSchema;
Expand All @@ -34,9 +35,9 @@

import static org.junit.Assert.assertEquals;

public class LastQueryScanNodeSerdeTest {
public class SourceNodeSerdeTest {
@Test
public void test() throws IllegalPathException {
public void testLastQueryScanNode() throws IllegalPathException {
LastQueryScanNode node =
new LastQueryScanNode(
new PlanNodeId("test"),
Expand Down Expand Up @@ -69,4 +70,19 @@ public void test() throws IllegalPathException {
byteBuffer.flip();
assertEquals(PlanNodeDeserializeHelper.deserialize(byteBuffer), node);
}

@Test
public void testShowQueriesNode() throws IllegalPathException {
ShowQueriesNode node = new ShowQueriesNode(new PlanNodeId("test"), null, "root");

ByteBuffer byteBuffer = ByteBuffer.allocate(2048);
node.serialize(byteBuffer);
byteBuffer.flip();
assertEquals(PlanNodeDeserializeHelper.deserialize(byteBuffer), node);
node = new ShowQueriesNode(new PlanNodeId("test"), null, "root");
byteBuffer = ByteBuffer.allocate(2048);
node.serialize(byteBuffer);
byteBuffer.flip();
assertEquals(PlanNodeDeserializeHelper.deserialize(byteBuffer), node);
}
}
Loading