Skip to content

Commit 35326e8

Browse files
authored
Disabled some unstable function (#17373)
* ob * it
1 parent b49aaac commit 35326e8

3 files changed

Lines changed: 222 additions & 18 deletions

File tree

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.it.schema;
21+
22+
import org.apache.iotdb.isession.ISession;
23+
import org.apache.iotdb.it.env.EnvFactory;
24+
import org.apache.iotdb.itbase.category.ClusterIT;
25+
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
26+
import org.apache.iotdb.util.AbstractSchemaIT;
27+
28+
import org.apache.tsfile.enums.TSDataType;
29+
import org.apache.tsfile.file.metadata.enums.CompressionType;
30+
import org.apache.tsfile.file.metadata.enums.TSEncoding;
31+
import org.apache.tsfile.write.record.Tablet;
32+
import org.junit.After;
33+
import org.junit.Assert;
34+
import org.junit.Test;
35+
import org.junit.experimental.categories.Category;
36+
import org.junit.runners.Parameterized;
37+
38+
import java.io.File;
39+
import java.nio.file.Files;
40+
import java.nio.file.Paths;
41+
import java.sql.Connection;
42+
import java.sql.Statement;
43+
import java.util.ArrayList;
44+
import java.util.Arrays;
45+
import java.util.Collections;
46+
import java.util.List;
47+
48+
@Category({LocalStandaloneIT.class, ClusterIT.class})
49+
public class IoTDBSchemaSyntaxIT extends AbstractSchemaIT {
50+
public IoTDBSchemaSyntaxIT(SchemaTestMode schemaTestMode) {
51+
super(schemaTestMode);
52+
}
53+
54+
@Parameterized.BeforeParam
55+
public static void before() throws Exception {
56+
setUpEnvironment();
57+
EnvFactory.getEnv().initClusterEnvironment();
58+
}
59+
60+
@Parameterized.AfterParam
61+
public static void after() throws Exception {
62+
EnvFactory.getEnv().cleanClusterEnvironment();
63+
tearDownEnvironment();
64+
}
65+
66+
@After
67+
public void tearDown() throws Exception {
68+
clearSchema();
69+
}
70+
71+
@Test
72+
public void testInvalidCreation() throws Exception {
73+
final List<String> invalidSQLs =
74+
Arrays.asList(
75+
"CREATE TIMESERIES root.sg1.d1.s1 OBJECT",
76+
"CREATE ALIGNED TIMESERIES root.sg1.d1.vector1(s1 OBJECT encoding=PLAIN compressor=UNCOMPRESSED,s2 INT64 encoding=RLE)",
77+
"create schema template t1 (s2 OBJECT encoding=RLE, s3 INT64 encoding=RLE compression=SNAPPY)");
78+
79+
try (final Connection connection = EnvFactory.getEnv().getConnection();
80+
final Statement statement = connection.createStatement()) {
81+
for (final String invalidSQL : invalidSQLs) {
82+
try {
83+
statement.execute(invalidSQL);
84+
Assert.fail();
85+
} catch (final Exception ignore) {
86+
// Expected
87+
}
88+
}
89+
}
90+
91+
final String testObject =
92+
System.getProperty("user.dir")
93+
+ File.separator
94+
+ "target"
95+
+ File.separator
96+
+ "test-classes"
97+
+ File.separator
98+
+ "object-example.pt";
99+
final byte[] objectBytes = Files.readAllBytes(Paths.get(testObject));
100+
final List<byte[]> objectSegments = new ArrayList<>();
101+
for (int i = 0; i < objectBytes.length; i += 512) {
102+
objectSegments.add(Arrays.copyOfRange(objectBytes, i, Math.min(i + 512, objectBytes.length)));
103+
}
104+
try (final ISession session = EnvFactory.getEnv().getSessionConnection()) {
105+
// insert table data by tablet
106+
final List<String> columnNameList =
107+
Arrays.asList("region_id", "plant_id", "device_id", "temperature", "file");
108+
final List<TSDataType> dataTypeList =
109+
Arrays.asList(
110+
TSDataType.STRING,
111+
TSDataType.STRING,
112+
TSDataType.STRING,
113+
TSDataType.FLOAT,
114+
TSDataType.OBJECT);
115+
final Tablet tablet = new Tablet(columnNameList, dataTypeList);
116+
tablet.setDeviceId("root.test.objectDevice");
117+
for (int i = 0; i < columnNameList.size() - 1; i++) {
118+
int rowIndex = tablet.getRowSize();
119+
tablet.addTimestamp(rowIndex, 1);
120+
tablet.addValue(rowIndex, 0, "1");
121+
tablet.addValue(rowIndex, 1, "5");
122+
tablet.addValue(rowIndex, 2, "3");
123+
tablet.addValue(rowIndex, 3, 37.6F);
124+
tablet.addValue(rowIndex, 4, false, i * 512L, objectSegments.get(i));
125+
}
126+
try {
127+
session.insertTablet(tablet);
128+
Assert.fail();
129+
} catch (final Exception ignore) {
130+
// Expected
131+
}
132+
try {
133+
session.insertAlignedTablet(tablet);
134+
Assert.fail();
135+
} catch (final Exception ignore) {
136+
// Expected
137+
}
138+
try {
139+
session.createMultiTimeseries(
140+
Collections.singletonList("root.sg1.d1.s1"),
141+
Collections.singletonList(TSDataType.OBJECT),
142+
Collections.singletonList(TSEncoding.PLAIN),
143+
Collections.singletonList(CompressionType.LZ4),
144+
null,
145+
null,
146+
null,
147+
null);
148+
} catch (final Exception ignore) {
149+
// Expected
150+
}
151+
tablet.reset();
152+
}
153+
}
154+
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutor.java

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.apache.iotdb.rpc.TSStatusCode;
8383
import org.apache.iotdb.trigger.api.enums.TriggerEvent;
8484

85+
import org.apache.tsfile.enums.TSDataType;
8586
import org.apache.tsfile.utils.Pair;
8687
import org.slf4j.Logger;
8788
import org.slf4j.LoggerFactory;
@@ -420,7 +421,12 @@ private RegionExecutionResult executeCreateTimeSeries(
420421
final ISchemaRegion schemaRegion =
421422
schemaEngine.getSchemaRegion((SchemaRegionId) context.getRegionId());
422423
final RegionExecutionResult result =
423-
checkQuotaBeforeCreatingTimeSeries(schemaRegion, node.getPath().getDevicePath(), 1);
424+
checkQuotaAndTypeBeforeCreatingTimeSeries(
425+
schemaRegion,
426+
node.getPath().getDevicePath(),
427+
1,
428+
Collections.singletonList(node.getPath().getMeasurement()),
429+
Collections.singletonList(node.getDataType()));
424430
if (result != null) {
425431
return result;
426432
}
@@ -475,8 +481,12 @@ private RegionExecutionResult executeCreateAlignedTimeSeries(
475481
final ISchemaRegion schemaRegion =
476482
schemaEngine.getSchemaRegion((SchemaRegionId) context.getRegionId());
477483
final RegionExecutionResult result =
478-
checkQuotaBeforeCreatingTimeSeries(
479-
schemaRegion, node.getDevicePath(), node.getMeasurements().size());
484+
checkQuotaAndTypeBeforeCreatingTimeSeries(
485+
schemaRegion,
486+
node.getDevicePath(),
487+
node.getMeasurements().size(),
488+
node.getMeasurements(),
489+
node.getDataTypes());
480490
if (result != null) {
481491
return result;
482492
}
@@ -533,8 +543,12 @@ private RegionExecutionResult executeCreateMultiTimeSeries(
533543
for (final Map.Entry<PartialPath, MeasurementGroup> entry :
534544
node.getMeasurementGroupMap().entrySet()) {
535545
result =
536-
checkQuotaBeforeCreatingTimeSeries(
537-
schemaRegion, entry.getKey(), entry.getValue().getMeasurements().size());
546+
checkQuotaAndTypeBeforeCreatingTimeSeries(
547+
schemaRegion,
548+
entry.getKey(),
549+
entry.getValue().getMeasurements().size(),
550+
entry.getValue().getMeasurements(),
551+
entry.getValue().getDataTypes());
538552
if (result != null) {
539553
return result;
540554
}
@@ -649,8 +663,12 @@ private RegionExecutionResult executeInternalCreateTimeSeries(
649663
final ISchemaRegion schemaRegion =
650664
schemaEngine.getSchemaRegion((SchemaRegionId) context.getRegionId());
651665
final RegionExecutionResult result =
652-
checkQuotaBeforeCreatingTimeSeries(
653-
schemaRegion, node.getDevicePath(), node.getMeasurementGroup().size());
666+
checkQuotaAndTypeBeforeCreatingTimeSeries(
667+
schemaRegion,
668+
node.getDevicePath(),
669+
node.getMeasurementGroup().size(),
670+
node.getMeasurementGroup().getMeasurements(),
671+
node.getMeasurementGroup().getDataTypes());
654672
if (result != null) {
655673
return result;
656674
}
@@ -736,8 +754,12 @@ private RegionExecutionResult executeInternalCreateMultiTimeSeries(
736754
for (final Map.Entry<PartialPath, Pair<Boolean, MeasurementGroup>> deviceEntry :
737755
node.getDeviceMap().entrySet()) {
738756
result =
739-
checkQuotaBeforeCreatingTimeSeries(
740-
schemaRegion, deviceEntry.getKey(), deviceEntry.getValue().getRight().size());
757+
checkQuotaAndTypeBeforeCreatingTimeSeries(
758+
schemaRegion,
759+
deviceEntry.getKey(),
760+
deviceEntry.getValue().getRight().size(),
761+
deviceEntry.getValue().getRight().getMeasurements(),
762+
deviceEntry.getValue().getRight().getDataTypes());
741763
if (result != null) {
742764
return result;
743765
}
@@ -823,8 +845,22 @@ private RegionExecutionResult executeInternalCreateMultiTimeSeries(
823845
*
824846
* @return null if the quota is not exceeded, otherwise return the execution result.
825847
*/
826-
private RegionExecutionResult checkQuotaBeforeCreatingTimeSeries(
827-
final ISchemaRegion schemaRegion, final PartialPath path, final int size) {
848+
private RegionExecutionResult checkQuotaAndTypeBeforeCreatingTimeSeries(
849+
final ISchemaRegion schemaRegion,
850+
final PartialPath path,
851+
final int size,
852+
final List<String> measurements,
853+
final List<TSDataType> dataTypes) {
854+
for (int i = 0; i < measurements.size(); ++i) {
855+
if (dataTypes.get(i) == TSDataType.OBJECT) {
856+
final String errorStr =
857+
"The object type series "
858+
+ path.concatAsMeasurementPath(measurements.get(i))
859+
+ " is not supported.";
860+
return RegionExecutionResult.create(
861+
false, errorStr, RpcUtils.getStatus(TSStatusCode.METADATA_ERROR, errorStr));
862+
}
863+
}
828864
try {
829865
schemaRegion.checkSchemaQuota(path, size);
830866
} catch (final SchemaQuotaExceededException e) {
@@ -949,8 +985,12 @@ private RegionExecutionResult executeActivateTemplate(
949985
ISchemaRegion schemaRegion =
950986
schemaEngine.getSchemaRegion((SchemaRegionId) context.getRegionId());
951987
RegionExecutionResult result =
952-
checkQuotaBeforeCreatingTimeSeries(
953-
schemaRegion, node.getActivatePath(), templateSetInfo.left.getMeasurementNumber());
988+
checkQuotaAndTypeBeforeCreatingTimeSeries(
989+
schemaRegion,
990+
node.getActivatePath(),
991+
templateSetInfo.left.getMeasurementNumber(),
992+
Collections.emptyList(),
993+
Collections.emptyList());
954994
if (result == null) {
955995
return receivedFromPipe
956996
? super.visitPipeEnrichedWritePlanNode(new PipeEnrichedWritePlanNode(node), context)
@@ -992,8 +1032,12 @@ private RegionExecutionResult executeBatchActivateTemplate(
9921032
false, message, RpcUtils.getStatus(TSStatusCode.METADATA_ERROR, message));
9931033
}
9941034
RegionExecutionResult result =
995-
checkQuotaBeforeCreatingTimeSeries(
996-
schemaRegion, devicePath, templateSetInfo.left.getMeasurementNumber());
1035+
checkQuotaAndTypeBeforeCreatingTimeSeries(
1036+
schemaRegion,
1037+
devicePath,
1038+
templateSetInfo.left.getMeasurementNumber(),
1039+
Collections.emptyList(),
1040+
Collections.emptyList());
9971041
if (result != null) {
9981042
return result;
9991043
}
@@ -1039,8 +1083,12 @@ private RegionExecutionResult executeInternalBatchActivateTemplate(
10391083
false, message, RpcUtils.getStatus(TSStatusCode.METADATA_ERROR, message));
10401084
}
10411085
RegionExecutionResult result =
1042-
checkQuotaBeforeCreatingTimeSeries(
1043-
schemaRegion, entry.getKey(), templateSetInfo.left.getMeasurementNumber());
1086+
checkQuotaAndTypeBeforeCreatingTimeSeries(
1087+
schemaRegion,
1088+
entry.getKey(),
1089+
templateSetInfo.left.getMeasurementNumber(),
1090+
Collections.emptyList(),
1091+
Collections.emptyList());
10441092
if (result != null) {
10451093
return result;
10461094
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4092,7 +4092,9 @@ private TSDataType parseDataTypeAttribute(IoTDBSqlParser.AttributeClausesContext
40924092
String dataTypeString = ctx.dataType.getText().toUpperCase();
40934093
try {
40944094
dataType = TSDataType.valueOf(dataTypeString);
4095-
if (TSDataType.UNKNOWN.equals(dataType) || TSDataType.VECTOR.equals(dataType)) {
4095+
if (TSDataType.UNKNOWN.equals(dataType)
4096+
|| TSDataType.VECTOR.equals(dataType)
4097+
|| TSDataType.OBJECT.equals(dataType)) {
40964098
throw new SemanticException(String.format(UNSUPPORTED_DATATYPE_MSG, dataTypeString));
40974099
}
40984100
} catch (Exception e) {

0 commit comments

Comments
 (0)