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 @@ -1275,6 +1275,23 @@ public void testInsertWithChangedSchema() throws SQLException, IOException {
}
}

@Test
public void testInsertWithTree() {
try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
Statement statement = connection.createStatement()) {
statement.execute("use \"test\"");
statement.execute("create table sg22 (tag1 string tag, s1 int64 field)");
statement.execute(
String.format(
"insert into root.test.sg22(tag1,time,s1) values('d1',%s,2)",
System.currentTimeMillis()));
fail();
} catch (Exception e) {
Assert.assertEquals(
"701: The tree model database shall not be specified in table model.", e.getMessage());
}
}

private List<Integer> checkHeader(
ResultSetMetaData resultSetMetaData, String expectedHeaderStrings, int[] expectedTypes)
throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void test() {
testInsertMultiPartition();
testInsertTablet();
testInsertTabletNoDatabase();
testInsertTabletWithTreeDB();
testInsertTablet1();
testInsertTablet2();
testQuery();
Expand Down Expand Up @@ -296,6 +297,18 @@ public void testInsertTabletNoDatabase() {
assertEquals(305, Integer.parseInt(result.get("code").toString()));
}

public void testInsertTabletWithTreeDB() {
List<String> sqls =
Collections.singletonList(
"create table sg211 (tag1 string tag,t1 STRING ATTRIBUTE, s1 FLOAT field)");
for (String sql : sqls) {
RestUtils.nonQuery(httpClient, port, sqlHandler("test", sql));
}
String json =
"{\"database\":\"root.test\",\"column_categories\":[\"TAG\",\"ATTRIBUTE\",\"FIELD\"],\"timestamps\":[1635232143960,1635232153960,1635232163960,1635232173960,1635232183960],\"column_names\":[\"tag1\",\"t1\",\"s1\"],\"data_types\":[\"STRING\",\"STRING\",\"FLOAT\"],\"values\":[[\"a11\",\"true\",11],[\"a11\",\"false\",22],[\"a13\",\"false1\",23],[\"a14\",\"false2\",24],[\"a15\",\"false3\",25]],\"table\":\"sg211\"}";
wrongInsertTablet(json);
}

public void testInsertTablet1() {
List<String> sqls =
Collections.singletonList(
Expand Down Expand Up @@ -340,6 +353,11 @@ public void rightInsertTablet(String json) {
assertEquals(11f, jsonArray1.get(2).getAsFloat(), 0f);
}

public void wrongInsertTablet(String json) {
JsonObject result = RestUtils.insertTablet(httpClient, port, json);
assertEquals(701, Integer.parseInt(result.get("code").toString()));
}

public void prepareTableData() {
for (int i = 0; i < sqls.length; i++) {
JsonObject jsonObject = new JsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.iotdb.commons.pipe.datastructure.pattern.TreePattern;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.pipe.event.common.PipeInsertionEvent;
import org.apache.iotdb.db.pipe.event.common.tsfile.parser.table.TsFileInsertionEventTableParser;
import org.apache.iotdb.db.pipe.metric.overview.PipeTsFileToTabletsMetrics;
import org.apache.iotdb.db.pipe.resource.PipeDataNodeResourceManager;
import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryBlock;
Expand All @@ -41,6 +42,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

public abstract class TsFileInsertionEventParser implements AutoCloseable {
Expand Down Expand Up @@ -76,6 +78,7 @@
protected Iterable<TabletInsertionEvent> tabletInsertionIterable;

protected TsFileInsertionEventParser(
final File tsFile,
final String pipeName,
final long creationTime,
final TreePattern treePattern,
Expand All @@ -85,7 +88,8 @@
final PipeTaskMeta pipeTaskMeta,
final IAuditEntity entity,
final boolean skipIfNoPrivileges,
final PipeInsertionEvent sourceEvent) {
final PipeInsertionEvent sourceEvent,
final boolean isWithMod) {
this.pipeName = pipeName;
this.creationTime = creationTime;
this.entity = entity;
Expand All @@ -107,6 +111,17 @@
PipeDataNodeResourceManager.memory()
.forceAllocateForTabletWithRetry(
IoTDBDescriptor.getInstance().getConfig().getPipeDataStructureTabletSizeInBytes());

LOGGER.info(
"TsFile {} has initialized {}, pipeName: {}, creation time: {}, pattern: {}, startTime: {}, endTime: {}, withMod: {}",

Check warning on line 116 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/parser/TsFileInsertionEventParser.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Line is longer than 100 characters (found 126).

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2aNSBWlbRe63qrXfFi&open=AZ2aNSBWlbRe63qrXfFi&pullRequest=17504
tsFile,
getClass().getSimpleName(),
pipeName,
creationTime,
this instanceof TsFileInsertionEventTableParser ? tablePattern : treePattern,
startTime,
endTime,
isWithMod);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public TsFileInsertionEventQueryParser(
final boolean isWithMod)
throws IOException, IllegalPathException {
super(
tsFile,
pipeName,
creationTime,
pattern,
Expand All @@ -140,7 +141,8 @@ public TsFileInsertionEventQueryParser(
pipeTaskMeta,
entity,
skipIfNoPrivileges,
sourceEvent);
sourceEvent,
isWithMod);

try {
currentModifications =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public TsFileInsertionEventScanParser(
final boolean isWithMod)
throws IOException, IllegalPathException {
super(
tsFile,
pipeName,
creationTime,
pattern,
Expand All @@ -127,7 +128,8 @@ public TsFileInsertionEventScanParser(
pipeTaskMeta,
entity,
skipIfNoPrivileges,
sourceEvent);
sourceEvent,
isWithMod);

this.startTime = startTime;
this.endTime = endTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public TsFileInsertionEventTableParser(
final boolean isWithMod)
throws IOException {
super(
tsFile,
pipeName,
creationTime,
null,
Expand All @@ -80,7 +81,8 @@ public TsFileInsertionEventTableParser(
pipeTaskMeta,
entity,
true,
sourceEvent);
sourceEvent,
isWithMod);

this.isWithMod = isWithMod;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

import org.apache.iotdb.commons.conf.IoTDBConstant.ClientVersion;
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.db.exception.sql.SemanticException;
import org.apache.iotdb.db.queryengine.common.ConnectionInfo;
import org.apache.iotdb.rpc.subscription.annotation.TableModel;
import org.apache.iotdb.service.rpc.thrift.TSConnectionInfo;
import org.apache.iotdb.service.rpc.thrift.TSConnectionType;

Expand All @@ -33,6 +36,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.time.ZoneId;
import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;

Expand Down Expand Up @@ -188,8 +192,15 @@ public String getDatabaseName() {
return databaseName;
}

@TableModel
public void setDatabaseName(@Nullable String databaseName) {
this.databaseName = databaseName;
if (Objects.nonNull(databaseName) && !PathUtils.isTableModelDatabase(databaseName)) {
throw new SemanticException(
"The database name "
+ databaseName
+ " is a tree model database, which is not allowed to set in the client session.");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
import org.apache.iotdb.commons.udf.builtin.relational.TableBuiltinScalarFunction;
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.exception.sql.SemanticException;
import org.apache.iotdb.db.protocol.session.IClientSession;
Expand Down Expand Up @@ -1987,7 +1988,7 @@
}

@Override
public Node visitGrantStatement(RelationalSqlParser.GrantStatementContext ctx) {

Check warning on line 1991 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.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 29 to 14, Nesting Level from 4 to 2, Number of Variables from 10 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2ZTv0LMFAHo6ysEnhJ&open=AZ2ZTv0LMFAHo6ysEnhJ&pullRequest=17504
boolean toUser;
String name;
toUser = ctx.holderType().getText().equalsIgnoreCase("user");
Expand Down Expand Up @@ -2072,7 +2073,7 @@
throw new SemanticException("author statement parser error");
}

public Node visitRevokeStatement(RelationalSqlParser.RevokeStatementContext ctx) {

Check warning on line 2076 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.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 89 to 64, Complexity from 27 to 14, Nesting Level from 4 to 2, Number of Variables from 9 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2ZTv0LMFAHo6ysEnhK&open=AZ2ZTv0LMFAHo6ysEnhK&pullRequest=17504
boolean fromUser;
String name;
fromUser = ctx.holderType().getText().equalsIgnoreCase("user");
Expand Down Expand Up @@ -4136,7 +4137,11 @@
}

private QualifiedName getQualifiedName(RelationalSqlParser.QualifiedNameContext context) {
return QualifiedName.of(visit(context.identifier(), Identifier.class));
final QualifiedName result = QualifiedName.of(visit(context.identifier(), Identifier.class));
if (!result.getPrefix().map(s -> PathUtils.isTableModelDatabase(s.toString())).orElse(true)) {
throw new SemanticException("The tree model database shall not be specified in table model.");
}
return result;
}

private static boolean isDistinct(RelationalSqlParser.SetQuantifierContext setQuantifier) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<argLine/>
<awaitility.version>4.2.0</awaitility.version>
<boost.include.dir/>
<bouncycastle.version>1.81</bouncycastle.version>
<bouncycastle.version>1.84</bouncycastle.version>
<!-- This was the last version to support Java 8 -->
<caffeine.version>2.9.3</caffeine.version>
<cglib.version>3.3.0</cglib.version>
Expand Down
Loading