Caideyipi commented on code in PR #14617: URL: https://github.com/apache/iotdb/pull/14617#discussion_r2049943228
########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TreeViewSchema.java: ########## @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.commons.schema.table; + +import org.apache.iotdb.commons.exception.IllegalPathException; +import org.apache.iotdb.commons.exception.IoTDBRuntimeException; +import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.commons.path.PathPatternUtil; +import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema; +import org.apache.iotdb.rpc.TSStatusCode; + +public class TreeViewSchema { + public static final String ORIGINAL_NAME = "__original_name"; + public static final String TREE_PATH_PATTERN = "__tree_path_pattern"; + public static final String RESTRICT = "__restrict"; + + public static boolean isTreeViewTable(final TsTable table) { + return table.getPropValue(TREE_PATH_PATTERN).isPresent(); + } + + public static PartialPath getPrefixPattern(final TsTable table) { + return table + .getPropValue(TreeViewSchema.TREE_PATH_PATTERN) + .map(TreeViewSchema::forceSeparateStringToPartialPath) + .orElseThrow( + () -> + new IoTDBRuntimeException( + String.format( + "Failed to get the original database, because the %s is null for table %s", + TreeViewSchema.TREE_PATH_PATTERN, table.getTableName()), + TSStatusCode.SEMANTIC_ERROR.getStatusCode())); + } + + public static PartialPath forceSeparateStringToPartialPath(final String string) { + final PartialPath partialPath; + try { + partialPath = new PartialPath(string); + } catch (final IllegalPathException e) { + throw new IoTDBRuntimeException( + String.format( + "Failed to parse the tree view string %s when convert to IDeviceID", string), + TSStatusCode.SEMANTIC_ERROR.getStatusCode()); + } + return partialPath; + } + + public static String getOriginalName(final TsTableColumnSchema schema) { + return schema.getProps().get(ORIGINAL_NAME); + } + + public static void setOriginalName(final TsTableColumnSchema schema, final String name) { + schema.getProps().put(ORIGINAL_NAME, name); + } + + public static boolean isRestrict(final TsTable table) { + return table.getPropValue(RESTRICT).isPresent(); + } + + public static void setRestrict(final TsTable table) { + table.addProp(RESTRICT, ""); + } + + public static String setPathPattern(final TsTable table, final PartialPath pathPattern) { + final String[] nodes = pathPattern.getNodes(); + if (!PathPatternUtil.isMultiLevelMatchWildcard(nodes[nodes.length - 1])) { + return "The last node must be '**'"; Review Comment: This class is in "common" and cannot throw the "SemanticException" because the latter one is in "server" module... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
