public static Schema parseSchema()

in java/tools/src/main/java/org/apache/tsfile/tools/SchemaParser.java [142:191]


  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=")) {
          schema.tableName = extractValue(line);
        } else if (line.startsWith("time_precision=")) {
          schema.timePrecision = extractValue(line);
        } else if (line.startsWith("has_header=")) {
          String has_header = extractValue(line);
          if (has_header.equals("true") || has_header.equals("false")) {
            schema.hasHeader = Boolean.parseBoolean(has_header);
          } else {
            throw new IllegalArgumentException("The data format of has_header is incorrect");
          }
        } else if (line.startsWith("separator=")) {
          schema.separator = extractValue(line);
        } else if (line.startsWith("null_format=")) {
          schema.nullFormat = extractValue(line);
        } else if (line.startsWith("time_column=")) {
          schema.timeColumn = extractValue(line);
        } else if (line.equals("id_columns")) {
          readingIdColumns = true;
          readingCsvColumns = false;
        } else if (line.equals("csv_columns")) {
          readingIdColumns = false;
          readingCsvColumns = true;
        } else if (readingIdColumns) {
          parseIdColumns(line, schema);
        } else if (readingCsvColumns) {
          parseCsvColumns(line, schema, timeIndex);
          timeIndex++;
        }
      }
      addIdColumnsIndex(schema);
    }
    validateParams(schema);
    if (schema.separator.equals("tab")) {
      schema.separator = "\t";
    }
    return schema;
  }