Skip to content

Commit eea7e65

Browse files
authored
Refactor: Renamed the remaining id columns to tag (#17582)
1 parent 38ea60e commit eea7e65

14 files changed

Lines changed: 74 additions & 74 deletions

File tree

iotdb-client/client-cpp/src/main/Session.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,14 @@ void Tablet::setAligned(bool isAligned) {
263263
}
264264

265265
std::shared_ptr<storage::IDeviceID> Tablet::getDeviceID(int row) {
266-
std::vector<std::string> id_array(idColumnIndexes.size() + 1);
267-
size_t idArrayIdx = 0;
268-
id_array[idArrayIdx++] = this->deviceId;
269-
for (auto idColumnIndex : idColumnIndexes) {
270-
void* strPtr = getValue(idColumnIndex, row, TSDataType::TEXT);
271-
id_array[idArrayIdx++] = *static_cast<std::string*>(strPtr);
272-
}
273-
return std::make_shared<storage::StringArrayDeviceID>(id_array);
266+
std::vector<std::string> deviceIdSegments(tagColumnIndexes.size() + 1);
267+
size_t deviceIdSegmentIndex = 0;
268+
deviceIdSegments[deviceIdSegmentIndex++] = this->deviceId;
269+
for (auto tagColumnIndex : tagColumnIndexes) {
270+
void* strPtr = getValue(tagColumnIndex, row, TSDataType::TEXT);
271+
deviceIdSegments[deviceIdSegmentIndex++] = *static_cast<std::string*>(strPtr);
272+
}
273+
return std::make_shared<storage::StringArrayDeviceID>(deviceIdSegments);
274274
}
275275

276276
string SessionUtils::getTime(const Tablet& tablet) {

iotdb-client/client-cpp/src/main/Session.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class Tablet {
135135
size_t rowSize; //the number of rows to include in this tablet
136136
size_t maxRowNumber; // the maximum number of rows for this tablet
137137
bool isAligned; // whether this tablet store data of aligned timeseries or not
138-
std::vector<int> idColumnIndexes;
138+
std::vector<int> tagColumnIndexes;
139139

140140
Tablet() = default;
141141

@@ -183,10 +183,10 @@ class Tablet {
183183
// create value columns
184184
values.resize(schemas.size());
185185
createColumns();
186-
// init idColumnIndexs
186+
// init tagColumnIndexes
187187
for (size_t i = 0; i < this->columnTypes.size(); i++) {
188188
if (this->columnTypes[i] == ColumnCategory::TAG) {
189-
idColumnIndexes.push_back(i);
189+
tagColumnIndexes.push_back(i);
190190
}
191191
}
192192
// create bitMaps
@@ -205,7 +205,7 @@ class Tablet {
205205
: deviceId(other.deviceId), schemas(other.schemas), schemaNameIndex(other.schemaNameIndex),
206206
columnTypes(other.columnTypes), timestamps(other.timestamps),
207207
maxRowNumber(other.maxRowNumber), bitMaps(other.bitMaps), rowSize(other.rowSize),
208-
isAligned(other.isAligned), idColumnIndexes(other.idColumnIndexes) {
208+
isAligned(other.isAligned), tagColumnIndexes(other.tagColumnIndexes) {
209209
values.resize(other.values.size());
210210
for (size_t i = 0; i < other.values.size(); ++i) {
211211
if (!other.values[i])
@@ -226,7 +226,7 @@ class Tablet {
226226
maxRowNumber = other.maxRowNumber;
227227
rowSize = other.rowSize;
228228
isAligned = other.isAligned;
229-
idColumnIndexes = other.idColumnIndexes;
229+
tagColumnIndexes = other.tagColumnIndexes;
230230
bitMaps = other.bitMaps;
231231
values.resize(other.values.size());
232232
for (size_t i = 0; i < other.values.size(); ++i) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DevicePredicateHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class DevicePredicateHandler implements AutoCloseable {
4747
protected final ColumnTransformer filterOutputTransformer;
4848
private final List<TSDataType> inputDataTypes;
4949
private final List<TsTableColumnSchema> columnSchemaList;
50-
private final int idIndex;
50+
private final int tagIndex;
5151

5252
// Batch logic
5353
protected static final int DEFAULT_MAX_TS_BLOCK_LINE_NUMBER =
@@ -72,7 +72,7 @@ protected DevicePredicateHandler(
7272
columnSchemaList.stream()
7373
.map(TsTableColumnSchema::getDataType)
7474
.collect(Collectors.toList());
75-
this.idIndex =
75+
this.tagIndex =
7676
PathUtils.isTableModelDatabase(database)
7777
? 3
7878
: DataNodeTreeViewSchemaUtils.getPatternNodes(table).length;
@@ -100,7 +100,7 @@ public void prepareBatchResult() {
100100
deviceSchemaBatch.forEach(
101101
deviceSchemaInfo ->
102102
transformToTableDeviceTsBlockColumns(
103-
deviceSchemaInfo, builder, columnSchemaList, idIndex));
103+
deviceSchemaInfo, builder, columnSchemaList, tagIndex));
104104
curBlock = builder.build();
105105
if (withoutFilter()) {
106106
return;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/TableDeviceFetchSource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ public void transformToTsBlockColumns(
8181
final IDeviceSchemaInfo schemaInfo, final TsBlockBuilder builder, final String database) {
8282
builder.getTimeColumnBuilder().writeLong(0L);
8383
int resultIndex = 0;
84-
int idIndex = 0;
84+
int tagIndex = 0;
8585
final String[] pathNodes = schemaInfo.getRawNodes();
8686
final TsTable table = DataNodeTableCache.getInstance().getTable(this.database, tableName);
8787
TsTableColumnSchema columnSchema;
8888
for (final ColumnHeader columnHeader : columnHeaderList) {
8989
columnSchema = table.getColumnSchema(columnHeader.getColumnName());
9090
if (columnSchema.getColumnCategory().equals(TsTableColumnCategory.TAG)) {
91-
if (pathNodes.length <= idIndex + 3 || pathNodes[idIndex + 3] == null) {
91+
if (pathNodes.length <= tagIndex + 3 || pathNodes[tagIndex + 3] == null) {
9292
builder.getColumnBuilder(resultIndex).appendNull();
9393
} else {
9494
builder
9595
.getColumnBuilder(resultIndex)
96-
.writeBinary(new Binary(pathNodes[idIndex + 3], TSFileConfig.STRING_CHARSET));
96+
.writeBinary(new Binary(pathNodes[tagIndex + 3], TSFileConfig.STRING_CHARSET));
9797
}
98-
idIndex++;
98+
tagIndex++;
9999
} else if (columnSchema.getColumnCategory().equals(TsTableColumnCategory.ATTRIBUTE)) {
100100
if (Objects.isNull(schemaInfo.getAttributeValue(columnHeader.getColumnName()))) {
101101
builder.getColumnBuilder(resultIndex).appendNull();

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -436,23 +436,23 @@ private static TableDeletionEntry parsePredicate(Expression expression, TsTable
436436
Queue<Expression> expressionQueue = new LinkedList<>();
437437
expressionQueue.add(expression);
438438
DeletionPredicate predicate = new DeletionPredicate(table.getTableName());
439-
IDPredicate idPredicate = null;
439+
IDPredicate tagPredicate = null;
440440
TimeRange timeRange = new TimeRange(Long.MIN_VALUE, Long.MAX_VALUE, true);
441441
while (!expressionQueue.isEmpty()) {
442442
Expression currExp = expressionQueue.remove();
443443
if (currExp instanceof LogicalExpression) {
444444
parseAndPredicate(((LogicalExpression) currExp), expressionQueue);
445445
} else if (currExp instanceof ComparisonExpression) {
446-
idPredicate =
447-
parseComparison(((ComparisonExpression) currExp), timeRange, idPredicate, table);
446+
tagPredicate =
447+
parseComparison(((ComparisonExpression) currExp), timeRange, tagPredicate, table);
448448
} else if (currExp instanceof IsNullPredicate) {
449-
idPredicate = parseIsNull((IsNullPredicate) currExp, idPredicate, table);
449+
tagPredicate = parseIsNull((IsNullPredicate) currExp, tagPredicate, table);
450450
} else {
451451
throw new SemanticException("Unsupported expression: " + currExp + " in " + expression);
452452
}
453453
}
454-
if (idPredicate != null) {
455-
predicate.setIdPredicate(idPredicate);
454+
if (tagPredicate != null) {
455+
predicate.setIdPredicate(tagPredicate);
456456
}
457457
if (timeRange.getStartTime() > timeRange.getEndTime()) {
458458
throw new SemanticException(
@@ -479,14 +479,14 @@ private static IDPredicate parseIsNull(
479479
throw new SemanticException("Left hand expression is not an identifier: " + leftHandExp);
480480
}
481481
String columnName = ((Identifier) leftHandExp).getValue();
482-
int idColumnOrdinal = table.getTagColumnOrdinal(columnName);
483-
if (idColumnOrdinal == -1) {
482+
int tagColumnOrdinal = table.getTagColumnOrdinal(columnName);
483+
if (tagColumnOrdinal == -1) {
484484
throw new SemanticException(
485485
"The column '" + columnName + "' does not exist or is not a tag column");
486486
}
487487

488488
// the first segment is the table name, so + 1
489-
IDPredicate newPredicate = new SegmentExactMatch(null, idColumnOrdinal + 1);
489+
IDPredicate newPredicate = new SegmentExactMatch(null, tagColumnOrdinal + 1);
490490
return combinePredicates(oldPredicate, newPredicate);
491491
}
492492

@@ -548,20 +548,20 @@ private static IDPredicate parseComparison(
548548

549549
return oldPredicate;
550550
}
551-
// id predicate
551+
// tag predicate
552552
String columnName = identifier.getValue();
553-
int idColumnOrdinal = table.getTagColumnOrdinal(columnName);
554-
if (idColumnOrdinal == -1) {
553+
int tagColumnOrdinal = table.getTagColumnOrdinal(columnName);
554+
if (tagColumnOrdinal == -1) {
555555
throw new SemanticException(
556556
"The column '" + columnName + "' does not exist or is not a tag column");
557557
}
558558

559-
IDPredicate newPredicate = getIdPredicate(comparisonExpression, right, idColumnOrdinal);
559+
IDPredicate newPredicate = getTagPredicate(comparisonExpression, right, tagColumnOrdinal);
560560
return combinePredicates(oldPredicate, newPredicate);
561561
}
562562

563-
private static IDPredicate getIdPredicate(
564-
ComparisonExpression comparisonExpression, Expression right, int idColumnOrdinal) {
563+
private static IDPredicate getTagPredicate(
564+
ComparisonExpression comparisonExpression, Expression right, int tagColumnOrdinal) {
565565
if (comparisonExpression.getOperator() != ComparisonExpression.Operator.EQUAL) {
566566
throw new SemanticException("The operator of tag predicate must be '=' for " + right);
567567
}
@@ -577,7 +577,7 @@ private static IDPredicate getIdPredicate(
577577
"The right hand value of tag predicate must be a string: " + right);
578578
}
579579
// the first segment is the table name, so + 1
580-
return new SegmentExactMatch(rightHandValue, idColumnOrdinal + 1);
580+
return new SegmentExactMatch(rightHandValue, tagColumnOrdinal + 1);
581581
}
582582

583583
public interface DataPartitionQueryFunc {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/CheckSchemaPredicateVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
import java.util.Objects;
4141

42-
// Return whether input expression can not be bounded to a single ID
42+
// Return whether the input expression can not be bounded by tag-only predicates.
4343
public class CheckSchemaPredicateVisitor
4444
implements AstVisitor<Boolean, CheckSchemaPredicateVisitor.Context> {
4545

@@ -57,7 +57,7 @@ public Boolean visitLogicalExpression(final LogicalExpression node, final Contex
5757
if (node.getOperator().equals(LogicalExpression.Operator.AND)) {
5858
if (System.currentTimeMillis() - lastLogTime >= LOG_INTERVAL_MS) {
5959
LOGGER.info(
60-
"And expression encountered during id determined checking, will be classified into fuzzy expression. Sql: {}",
60+
"And expression encountered during tag-determined checking, will be classified into fuzzy expression. Sql: {}",
6161
context.queryContext.getSql());
6262
lastLogTime = System.currentTimeMillis();
6363
}
@@ -75,7 +75,7 @@ public Boolean visitNotExpression(final NotExpression node, final Context contex
7575
if (node.getValue().getExpressionType().equals(TableExpressionType.LOGICAL_EXPRESSION)) {
7676
if (System.currentTimeMillis() - lastLogTime >= LOG_INTERVAL_MS) {
7777
LOGGER.info(
78-
"Logical expression type encountered in not expression child during id determined checking, will be classified into fuzzy expression. Sql: {}",
78+
"Logical expression type encountered in not expression child during tag-determined checking, will be classified into fuzzy expression. Sql: {}",
7979
context.queryContext.getSql());
8080
lastLogTime = System.currentTimeMillis();
8181
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/ConvertSchemaPredicateToFilterVisitor.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
/**
6969
* The {@link ConvertSchemaPredicateToFilterVisitor} will convert a predicate to {@link
7070
* SchemaFilter}. For the predicates which can not be converted, this will return {@code null}.
71-
* However, for IdDeterminedPredicate, this visitor shall never return {@code null}.
71+
* However, for tag-determined predicates, this visitor shall never return {@code null}.
7272
*/
7373
public class ConvertSchemaPredicateToFilterVisitor
7474
extends PredicateVisitor<SchemaFilter, ConvertSchemaPredicateToFilterVisitor.Context> {
@@ -84,7 +84,7 @@ public class ConvertSchemaPredicateToFilterVisitor
8484
}
8585
}
8686

87-
return wrapIdOrAttributeFilter(
87+
return wrapTagOrAttributeFilter(
8888
new InFilter(
8989
values.stream()
9090
.map(value -> ((StringLiteral) value).getValue())
@@ -95,14 +95,14 @@ public class ConvertSchemaPredicateToFilterVisitor
9595

9696
@Override
9797
public SchemaFilter visitIsNullPredicate(final IsNullPredicate node, final Context context) {
98-
return wrapIdOrAttributeFilter(
98+
return wrapTagOrAttributeFilter(
9999
new PreciseFilter((String) null), ((SymbolReference) node.getValue()).getName(), context);
100100
}
101101

102102
@Override
103103
public SchemaFilter visitIsNotNullPredicate(
104104
final IsNotNullPredicate node, final Context context) {
105-
return wrapIdOrAttributeFilter(
105+
return wrapTagOrAttributeFilter(
106106
new NotFilter(new PreciseFilter((String) null)),
107107
((SymbolReference) node.getValue()).getName(),
108108
context);
@@ -111,12 +111,12 @@ public SchemaFilter visitIsNotNullPredicate(
111111
@Override
112112
public @Nullable SchemaFilter visitLikePredicate(
113113
final LikePredicate node, final Context context) {
114-
// TODO: Support stringLiteral like id/attr?
114+
// TODO: Support stringLiteral like tag/attr?
115115
if (!(node.getValue() instanceof SymbolReference)
116116
|| !(node.getPattern() instanceof StringLiteral)) {
117117
return null;
118118
}
119-
return wrapIdOrAttributeFilter(
119+
return wrapTagOrAttributeFilter(
120120
new LikeFilter(
121121
(((StringLiteral) node.getPattern()).getValue()),
122122
node.getEscape().isPresent()
@@ -174,7 +174,7 @@ public SchemaFilter visitIsNotNullPredicate(
174174
return null;
175175
}
176176

177-
return wrapIdOrAttributeFilter(
177+
return wrapTagOrAttributeFilter(
178178
node.getOperator() == ComparisonExpression.Operator.EQUAL
179179
? new PreciseFilter(value)
180180
: new ComparisonFilter(
@@ -236,35 +236,35 @@ public SchemaFilter visitBetweenPredicate(final BetweenPredicate node, final Con
236236
return visitExpression(node, context);
237237
}
238238

239-
private SchemaFilter wrapIdOrAttributeFilter(
239+
private SchemaFilter wrapTagOrAttributeFilter(
240240
final SchemaFilter filter, final String columnName, final Context context) {
241241
return context
242242
.table
243243
.getColumnSchema(columnName)
244244
.getColumnCategory()
245245
.equals(TsTableColumnCategory.TAG)
246-
? new TagFilter(filter, context.idColumnIndexMap.get(columnName))
246+
? new TagFilter(filter, context.tagColumnIndexMap.get(columnName))
247247
: new AttributeFilter(filter, columnName);
248248
}
249249

250250
public static class Context {
251251

252252
private final TsTable table;
253-
private final Map<String, Integer> idColumnIndexMap;
253+
private final Map<String, Integer> tagColumnIndexMap;
254254

255255
public Context(final TsTable table) {
256256
this.table = table;
257-
this.idColumnIndexMap = getIdColumnIndex(table);
257+
this.tagColumnIndexMap = getTagColumnIndex(table);
258258
}
259259

260-
private Map<String, Integer> getIdColumnIndex(final TsTable table) {
260+
private Map<String, Integer> getTagColumnIndex(final TsTable table) {
261261
Map<String, Integer> map = new HashMap<>();
262262
List<TsTableColumnSchema> columnSchemaList = table.getColumnList();
263-
int idIndex = 0;
263+
int tagIndex = 0;
264264
for (TsTableColumnSchema columnSchema : columnSchemaList) {
265265
if (columnSchema.getColumnCategory().equals(TsTableColumnCategory.TAG)) {
266-
map.put(columnSchema.getColumnName(), idIndex);
267-
idIndex++;
266+
map.put(columnSchema.getColumnName(), tagIndex);
267+
tagIndex++;
268268
}
269269
}
270270
return map;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/ExtractPredicateColumnNameVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ExtractPredicateColumnNameVisitor extends PredicateVisitor<String,
4141
@Override
4242
public String visitExpression(final Expression expression, final Void context) {
4343
// TODO: implement schema function filter and parse some function call and arithmetic filters
44-
// into id determined filter
44+
// into a tag-determined filter
4545
return null;
4646
}
4747

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/SchemaPredicateUtil.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public class SchemaPredicateUtil {
5151

5252
private SchemaPredicateUtil() {}
5353

54-
// pair.left is Expressions only contain ID columns
55-
// pair.right is Expressions contain at least one ATTRIBUTE column
54+
// pair.left is expressions that only contain tag columns
55+
// pair.right is expressions that contain at least one attribute column
5656
static Pair<List<Expression>, List<Expression>> separateTagDeterminedPredicate(
5757
final List<Expression> expressionList,
5858
final TsTable table,
@@ -71,7 +71,7 @@ static Pair<List<Expression>, List<Expression>> separateTagDeterminedPredicate(
7171
final BetweenPredicate predicate = (BetweenPredicate) expression;
7272

7373
// Separate the between predicate to simplify the logic and to handle cases like '2' between
74-
// id1 and attr2 / id1 between '2' and attr1
74+
// tag1 and attr2 / tag1 between '2' and attr1
7575
separateExpression(
7676
new ComparisonExpression(
7777
ComparisonExpression.Operator.LESS_THAN_OR_EQUAL,
@@ -114,7 +114,7 @@ private static void separateExpression(
114114
// return or concat filter list, inner which all filter is and concat
115115
// e.g. (a OR b) AND (c OR d) -> (a AND c) OR (a AND d) OR (b AND c) OR (b AND d)
116116
// if input is empty, then return [[]]
117-
static List<Map<Integer, List<SchemaFilter>>> convertDeviceIdPredicateToOrConcatList(
117+
static List<Map<Integer, List<SchemaFilter>>> convertTagPredicateToOrConcatList(
118118
final List<Expression> schemaFilterList,
119119
final TsTable table,
120120
final AtomicBoolean mayContainDuplicateDevice) {
@@ -181,7 +181,7 @@ private static boolean handleFilter(
181181
final int index = ((TagFilter) currentFilter).getIndex();
182182
final SchemaFilter childFilter = currentFilter.getChild();
183183

184-
// Compress the not filters and put them after idFilter,
184+
// Compress the not filters and put them after the tag filter,
185185
// to simplify the logics in schema regions
186186
if (isNotFilter) {
187187
currentFilter.setChild(new NotFilter(childFilter));
@@ -223,10 +223,10 @@ static List<Integer> extractTagSingleMatchExpressionCases(
223223
final List<Map<Integer, List<SchemaFilter>>> index2FilterMapList,
224224
final TsTable tableInstance) {
225225
final List<Integer> selectedExpressionCases = new ArrayList<>();
226-
final int idCount = tableInstance.getTagNum();
226+
final int tagCount = tableInstance.getTagNum();
227227
for (int i = 0; i < index2FilterMapList.size(); i++) {
228228
final Map<Integer, List<SchemaFilter>> filterMap = index2FilterMapList.get(i);
229-
if (filterMap.size() == idCount
229+
if (filterMap.size() == tagCount
230230
&& filterMap.values().stream()
231231
.allMatch(
232232
filterList ->
@@ -242,7 +242,7 @@ static List<Integer> extractTagSingleMatchExpressionCases(
242242
}
243243

244244
// compact and-concat expression list to one expression
245-
static Expression compactDeviceIdFuzzyPredicate(final List<Expression> expressionList) {
245+
static Expression compactTagFuzzyPredicate(final List<Expression> expressionList) {
246246
if (expressionList.isEmpty()) {
247247
return null;
248248
}

0 commit comments

Comments
 (0)