All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.iotdb.schema.PathCheckExample Maven / Gradle / Ivy

The newest version!
/*
 * 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.schema;

import org.apache.iotdb.tsfile.exception.PathParseException;
import org.apache.iotdb.tsfile.read.common.parser.PathNodesGenerator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Before creating paths in IoTDB, it's essential to check whether the paths are correct to avoid
 * errors.
 *
 * 

This example checks the paths . You can add paths to the inputList or read paths from files * generated by export-csv.sh/export-csv.bat. * *

The usage of export-csv.sh can be found in the documentation. * For example: ./export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td . -q "show timeseries" */ public class PathCheckExample { private static final List INPUT_LIST = new ArrayList<>(); private static final String DIR = "/Users/root/iotdb/tools"; private static final Logger LOGGER = LoggerFactory.getLogger(PathCheckExample.class); // concurrent thread of path check private static final int CONCURRENCY = 5; public static void main(String[] args) { batchCheck(); dirCheck(); } private static void batchCheck() { INPUT_LIST.add("root.test.d1.s1"); INPUT_LIST.add("root.b+.d1.s2"); INPUT_LIST.add("root.test.1.s3"); INPUT_LIST.add("root.test.d-j.s4"); INPUT_LIST.add("root.test.'8`7'.s5"); INPUT_LIST.add("root.test.`1`.s6"); INPUT_LIST.add("root.test.\"d+b\".s7"); for (String path : INPUT_LIST) { checkPath(path); } } // This function wile check whether the paths are correct in current version. private static void checkPath(String path) { try { PathNodesGenerator.checkPath(path); } catch (PathParseException e) { LOGGER.error("{} is not a legal path.", path); } } /** * Using multiple threads to check the paths in the files of the directory. the files are created * by export-csv.sh/export-csv.bat. */ public static void dirCheck() { List> futureList = new ArrayList<>(); ExecutorService executorService = Executors.newFixedThreadPool(CONCURRENCY); File dir = new File(DIR); for (File file : Objects.requireNonNull(dir.listFiles())) { if (file.getName().startsWith("dump") && file.getName().endsWith(".csv")) { Future future = executorService.submit(new CheckThread(file)); futureList.add(future); } } try { for (Future future : futureList) { future.get(); } } catch (InterruptedException | ExecutionException e) { LOGGER.error("Error when checking paths."); Thread.currentThread().interrupt(); } executorService.shutdown(); } static class CheckThread implements Callable { File file; public CheckThread(File file) { this.file = file; } @Override public Void call() { try (BufferedReader br = new BufferedReader(new FileReader(file))) { String line = br.readLine(); while ((line = br.readLine()) != null) { String[] split = line.split(","); String path = split[0]; checkPath(path); } } catch (IOException e) { LOGGER.error("Error reading file: {}", file.getName()); throw new RuntimeException(e); } return null; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy