alpass163 commented on code in PR #18874:
URL: https://github.com/apache/iotdb/pull/18874#discussion_r4312270639
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/TreeDeviceViewFieldDetector.java:
##########
@@ -64,98 +65,191 @@ public class TreeDeviceViewFieldDetector {
private final ConfigManager configManager;
private final PartialPath path;
private final TsTable table;
- private final Map<String, Set<FieldColumnSchema>> fields;
private TDeviceViewResp result = new TDeviceViewResp(StatusUtils.OK, new
ConcurrentHashMap<>());
private final Map<String, String> lowerCase2OriginalMap = new HashMap<>();
- public TreeDeviceViewFieldDetector(
- final ConfigManager configManager,
- final TsTable table,
- final Map<String, Set<FieldColumnSchema>> fields) {
+ public TreeDeviceViewFieldDetector(final ConfigManager configManager, final
TsTable table) {
this.configManager = configManager;
this.path = TreeViewSchema.getPrefixPattern(table);
this.table = table;
- this.fields = fields;
}
- public TSStatus detectMissingFieldTypes() {
- if (table.getFieldNum() == 0 && Objects.isNull(fields)) {
+ /**
+ * Fills the fields of the view which is being created: a view may declare
no field at all, in
+ * which case every field under its tree path pattern becomes a column, or
declare fields whose
+ * type is left to the detection.
+ */
+ public TSStatus detectFieldsForCreation() {
+ if (table.getFieldNum() == 0) {
+ // for the first time creation of the table, user do not assign any
field;
+ // just detect all the fields of prefix path
new TreeDeviceViewFieldDetectionTaskExecutor(
configManager,
getLatestSchemaRegionMap(),
table.getTagNum(),
- TreeViewSchema.isRestrict(table))
+ TreeViewSchema.isRestrict(table),
+ null,
+ false)
.execute();
if (result.getStatus().getCode() !=
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return result.getStatus();
}
result
.getDeviewViewFieldTypeMap()
.forEach(
- (field, type) -> {
- final FieldColumnSchema columnSchema =
- new FieldColumnSchema(field,
TSDataType.getTsDataType(type));
- if (!field.equals(lowerCase2OriginalMap.get(field))) {
- TreeViewSchema.setOriginalName(columnSchema,
lowerCase2OriginalMap.get(field));
- }
- table.addColumnSchema(columnSchema);
- });
- } else {
- final Map<String, Set<FieldColumnSchema>> unknownFields;
- if (Objects.isNull(fields)) {
- unknownFields = new HashMap<>();
- for (final TsTableColumnSchema schema : table.getColumnList()) {
- if (!(schema instanceof FieldColumnSchema)
- || schema.getDataType() != TSDataType.UNKNOWN) {
- continue;
- }
- final String key = TreeViewSchema.getSourceName(schema);
- if (!unknownFields.containsKey(key)) {
- unknownFields.put(key, new HashSet<>());
- }
- unknownFields.get(key).add((FieldColumnSchema) schema);
- }
- } else {
- unknownFields = fields;
- }
+ (field, type) ->
+
table.addColumnSchema(toFieldColumnSchemaWithOriginName(field, type)));
+ return StatusUtils.OK;
+ }
+
+ return detectFieldTypes(collectUnknownFieldColumns());
+ }
+
+ /**
+ * Resolves the type of the field columns which are being added to an
existing view. The columns
+ * to resolve are given by the caller, as only it knows which ones it is
adding.
+ */
+ public TSStatus detectFieldTypesForColumnAddition(final Map<String,
FieldColumnSchema> fields) {
+ return detectFieldTypes(fields);
+ }
+
+ /**
+ * The fields which exist under the view's tree path pattern but are not
columns of the view yet,
+ * as the columns to add. Used after a view is created, to pick up the
series which were created
+ * before the view was mounted on the DataNodes, and which the DataNodes
therefore never reported.
+ */
+ public Pair<TSStatus, List<TsTableColumnSchema>>
detectNewFieldColumnsAfterCreation() {
+ new TreeDeviceViewFieldDetectionTaskExecutor(
+ configManager,
+ getLatestSchemaRegionMap(),
+ table.getTagNum(),
+ TreeViewSchema.isRestrict(table),
+ null,
+ true)
Review Comment:
only throw exception when create view, after that, the dectector apply the
"first detect, first add" principle
--
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]