CloudWise-Lukemiao commented on code in PR #139:
URL: https://github.com/apache/tsfile/pull/139#discussion_r1665332250


##########
java/tools/src/main/java/org/apache/tsfile/tools/SchemaParser.java:
##########
@@ -0,0 +1,271 @@
+/*
+ * 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.tsfile.tools;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class SchemaParser {
+
+  public static class Schema {
+    String tableName;
+    String timePrecision;
+    boolean hasHeader = true;
+    String separator;
+    String nullFormat;
+    String timeColumn;
+    int timeColumnIndex = -1;
+    List<IDColumns> idColumns = new ArrayList<>();
+    List<Column> csvColumns = new ArrayList<>();
+
+    @Override
+    public String toString() {
+      return "Schema{"
+          + "tableName='"
+          + tableName
+          + '\''
+          + ", timePrecision='"
+          + timePrecision
+          + '\''
+          + ", hasHeader="
+          + hasHeader
+          + ", separator='"
+          + separator
+          + '\''
+          + ", nullFormat='"
+          + nullFormat
+          + '\''
+          + ", timeColumn='"
+          + timeColumn
+          + '\''
+          + ", idColumns="
+          + idColumns
+          + ", csvColumns="
+          + csvColumns
+          + '}';
+    }
+  }
+
+  public static class Column {
+    String name;
+    String type;
+
+    boolean isSkip;
+
+    public Column(String name, String type) {
+      this.name = name;
+      this.isSkip = false;
+      this.type = type;
+    }
+
+    public Column(String name) {
+      this.name = name;
+      this.isSkip = true;
+    }
+
+    @Override
+    public String toString() {
+      return "Column{"
+          + "name='"
+          + name
+          + '\''
+          + ", type='"
+          + type
+          + '\''
+          + ", isSkip="
+          + isSkip
+          + '}';
+    }
+  }
+
+  public static class IDColumns {
+    String name;
+    boolean isDefault;
+    String defaultValue;
+    int csvColumnIndex = -1;
+    boolean isExistCsvColumn;
+
+    public IDColumns(String name, boolean isDefault, String defaultValue) {
+      this.name = name;
+      this.isDefault = isDefault;
+      if (isDefault) {
+        this.defaultValue = defaultValue;
+        this.isExistCsvColumn = false;
+      }
+    }
+
+    public IDColumns(String name) {
+      this.name = name;
+      this.isDefault = false;
+      this.isExistCsvColumn = true;
+    }
+
+    @Override
+    public String toString() {
+      return "IDColumns{"
+          + "name='"
+          + name
+          + '\''
+          + ", isDefault="
+          + isDefault
+          + ", defaultValue='"
+          + defaultValue
+          + '\''
+          + ", isExistCsvColumn="
+          + isExistCsvColumn
+          + ", csvColumnIndex="
+          + csvColumnIndex
+          + '}';
+    }
+  }
+
+  public static Schema parseSchema(String filePath) throws IOException {
+    Schema schema = new Schema();
+    try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) 
{
+      String line;
+      boolean readingIdColumns = false;
+      boolean readingCsvColumns = false;
+      int timeIndex = 0;
+      while ((line = reader.readLine()) != null) {
+        line = line.trim();
+        if (line.isEmpty() || line.startsWith("//")) continue;
+
+        if (line.startsWith("table_name=")) {

Review Comment:
   Fixed



-- 
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]

Reply via email to