1919
2020package org .apache .iotdb .db .queryengine .plan .relational .analyzer ;
2121
22+ import org .apache .iotdb .commons .exception .IoTDBException ;
2223import org .apache .iotdb .commons .schema .table .TsTable ;
2324import org .apache .iotdb .commons .schema .table .column .TsTableColumnCategory ;
2425import org .apache .iotdb .commons .schema .table .column .TsTableColumnSchema ;
@@ -550,9 +551,24 @@ protected Scope visitUpdate(final Update node, final Optional<Scope> context) {
550551 }
551552 attributeNames .add ((SymbolReference ) parsedColumn );
552553
553- final Pair <Type , Expression > expressionPair =
554- analyzeAndRewriteExpression (
555- translationMap , translationMap .getScope (), assignment .getValue ());
554+ final Pair <Type , Expression > expressionPair ;
555+ try {
556+ expressionPair =
557+ analyzeAndRewriteExpression (
558+ translationMap , translationMap .getScope (), assignment .getValue ());
559+ } catch (final Exception e ) {
560+ if (e .getMessage ().contains ("cannot be resolved" )) {
561+ throw new SemanticException (
562+ new IoTDBException (
563+ e .getCause ()
564+ .getMessage ()
565+ .replace (
566+ "cannot be resolved" ,
567+ "is not an attribute or tag column" ),
568+ TSStatusCode .SEMANTIC_ERROR .getStatusCode ()));
569+ }
570+ throw e ;
571+ }
556572 if (!expressionPair .getLeft ().equals (StringType .STRING )
557573 && !expressionPair .getLeft ().equals (BinaryType .TEXT )
558574 && !expressionPair .getLeft ().equals (UnknownType .UNKNOWN )) {
@@ -4545,11 +4561,24 @@ private TranslationMap analyzeTraverseDevice(
45454561
45464562 final TableSchema originalSchema = tableSchema .get ();
45474563 final ImmutableList .Builder <Field > fields = ImmutableList .builder ();
4564+ // We only leave attribute & tag here because the others are not allowed in device related
4565+ // SQLs
45484566 fields .addAll (
45494567 analyzeTableOutputFields (
45504568 node .getTable (),
45514569 name ,
4552- new TableSchema (originalSchema .getTableName (), originalSchema .getColumns ())));
4570+ new TableSchema (
4571+ originalSchema .getTableName (),
4572+ originalSchema .getColumns ().stream ()
4573+ .filter (
4574+ columnSchema ->
4575+ columnSchema
4576+ .getColumnCategory ()
4577+ .equals (TsTableColumnCategory .ATTRIBUTE )
4578+ || columnSchema
4579+ .getColumnCategory ()
4580+ .equals (TsTableColumnCategory .TAG ))
4581+ .collect (Collectors .toList ()))));
45534582 final List <Field > fieldList = fields .build ();
45544583 final Scope scope = createAndAssignScope (node , context , fieldList );
45554584 translationMap =
@@ -4563,7 +4592,19 @@ private TranslationMap analyzeTraverseDevice(
45634592 new PlannerContext (metadata , null ));
45644593
45654594 if (node .getWhere ().isPresent ()) {
4566- analyzeWhere (node , translationMap .getScope (), node .getWhere ().get ());
4595+ try {
4596+ analyzeWhere (node , translationMap .getScope (), node .getWhere ().get ());
4597+ } catch (final Throwable e ) {
4598+ if (e instanceof SemanticException && e .getMessage ().contains ("cannot be resolved" )) {
4599+ throw new SemanticException (
4600+ new IoTDBException (
4601+ e .getCause ()
4602+ .getMessage ()
4603+ .replace ("cannot be resolved" , "is not an attribute or tag column" ),
4604+ TSStatusCode .SEMANTIC_ERROR .getStatusCode ()));
4605+ }
4606+ throw e ;
4607+ }
45674608 node .setWhere (translationMap .rewrite (analysis .getWhere (node )));
45684609 }
45694610 }
0 commit comments