Skip to content

Commit 8a6e31f

Browse files
2b3c5112b3c511
and
2b3c511
authored
add import-schema.sh/bat and export-schema.sh/bat in cli/tools (apache#12623)
* add import-schema.sh/bat and export-schema.sh/bat in cli/tools * update it * update it --------- Co-authored-by: 2b3c511 <[email protected]>
1 parent 3d3fd86 commit 8a6e31f

File tree

9 files changed

+1748
-0
lines changed

9 files changed

+1748
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.iotdb.tools.it;
20+
21+
import org.apache.iotdb.cli.it.AbstractScript;
22+
import org.apache.iotdb.isession.ISession;
23+
import org.apache.iotdb.it.env.EnvFactory;
24+
import org.apache.iotdb.it.framework.IoTDBTestRunner;
25+
import org.apache.iotdb.itbase.category.ClusterIT;
26+
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
27+
import org.apache.iotdb.rpc.IoTDBConnectionException;
28+
import org.apache.iotdb.rpc.StatementExecutionException;
29+
30+
import org.apache.tsfile.enums.TSDataType;
31+
import org.apache.tsfile.file.metadata.enums.CompressionType;
32+
import org.apache.tsfile.file.metadata.enums.TSEncoding;
33+
import org.junit.AfterClass;
34+
import org.junit.BeforeClass;
35+
import org.junit.Test;
36+
import org.junit.experimental.categories.Category;
37+
import org.junit.runner.RunWith;
38+
39+
import java.io.File;
40+
import java.io.IOException;
41+
42+
@RunWith(IoTDBTestRunner.class)
43+
@Category({LocalStandaloneIT.class, ClusterIT.class})
44+
public class ExportSchemaTestIT extends AbstractScript {
45+
private static String ip;
46+
47+
private static String port;
48+
49+
private static String toolsPath;
50+
51+
private static String libPath;
52+
53+
private static String homePath;
54+
55+
@BeforeClass
56+
public static void setUp() throws Exception {
57+
EnvFactory.getEnv().initClusterEnvironment();
58+
ip = EnvFactory.getEnv().getIP();
59+
port = EnvFactory.getEnv().getPort();
60+
toolsPath = EnvFactory.getEnv().getToolsPath();
61+
libPath = EnvFactory.getEnv().getLibPath();
62+
homePath =
63+
libPath.substring(0, libPath.lastIndexOf(File.separator + "lib" + File.separator + "*"));
64+
}
65+
66+
@AfterClass
67+
public static void tearDown() throws Exception {
68+
EnvFactory.getEnv().cleanClusterEnvironment();
69+
}
70+
71+
@Test
72+
public void test() throws IOException {
73+
String os = System.getProperty("os.name").toLowerCase();
74+
if (os.startsWith("windows")) {
75+
testOnWindows();
76+
} else {
77+
testOnUnix();
78+
}
79+
}
80+
81+
@Override
82+
protected void testOnWindows() throws IOException {
83+
prepareSchema();
84+
final String[] output = {"Export completely!"};
85+
ProcessBuilder builder =
86+
new ProcessBuilder(
87+
"cmd.exe",
88+
"/c",
89+
toolsPath + File.separator + "export-schema.bat",
90+
"-h",
91+
ip,
92+
"-p",
93+
port,
94+
"-u",
95+
"root",
96+
"-pw",
97+
"root",
98+
"-t",
99+
"target",
100+
"-path",
101+
"root.**",
102+
"&",
103+
"exit",
104+
"%^errorlevel%");
105+
builder.environment().put("IOTDB_HOME", homePath);
106+
testOutput(builder, output, 0);
107+
}
108+
109+
@Override
110+
protected void testOnUnix() throws IOException {
111+
prepareSchema();
112+
final String[] output = {"Export completely!"};
113+
ProcessBuilder builder =
114+
new ProcessBuilder(
115+
"bash",
116+
toolsPath + File.separator + "export-schema.sh",
117+
"-h",
118+
ip,
119+
"-p",
120+
port,
121+
"-u",
122+
"root",
123+
"-pw",
124+
"root",
125+
"-t",
126+
"target",
127+
"-path",
128+
"root.**");
129+
builder.environment().put("IOTDB_HOME", homePath);
130+
testOutput(builder, output, 0);
131+
}
132+
133+
public void prepareSchema() {
134+
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
135+
session.open();
136+
session.createTimeseries(
137+
"root.schema.t2.c1",
138+
TSDataType.DOUBLE,
139+
TSEncoding.GORILLA,
140+
CompressionType.LZ4,
141+
null,
142+
null,
143+
null,
144+
null);
145+
} catch (IoTDBConnectionException | StatementExecutionException e) {
146+
throw new RuntimeException(e);
147+
}
148+
}
149+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.tools.it;
21+
22+
import org.apache.iotdb.cli.it.AbstractScript;
23+
import org.apache.iotdb.it.env.EnvFactory;
24+
import org.apache.iotdb.it.framework.IoTDBTestRunner;
25+
import org.apache.iotdb.itbase.category.ClusterIT;
26+
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
27+
28+
import org.junit.AfterClass;
29+
import org.junit.BeforeClass;
30+
import org.junit.Test;
31+
import org.junit.experimental.categories.Category;
32+
import org.junit.runner.RunWith;
33+
34+
import java.io.File;
35+
import java.io.IOException;
36+
37+
@RunWith(IoTDBTestRunner.class)
38+
@Category({LocalStandaloneIT.class, ClusterIT.class})
39+
public class ImportSchemaTestIT extends AbstractScript {
40+
41+
private static String ip;
42+
43+
private static String port;
44+
45+
private static String toolsPath;
46+
47+
private static String libPath;
48+
49+
private static String homePath;
50+
51+
@BeforeClass
52+
public static void setUp() {
53+
EnvFactory.getEnv().initClusterEnvironment();
54+
ip = EnvFactory.getEnv().getIP();
55+
port = EnvFactory.getEnv().getPort();
56+
toolsPath = EnvFactory.getEnv().getToolsPath();
57+
libPath = EnvFactory.getEnv().getLibPath();
58+
homePath =
59+
libPath.substring(0, libPath.lastIndexOf(File.separator + "lib" + File.separator + "*"));
60+
}
61+
62+
@AfterClass
63+
public static void tearDown() {
64+
EnvFactory.getEnv().cleanClusterEnvironment();
65+
}
66+
67+
@Test
68+
public void test() throws IOException {
69+
String os = System.getProperty("os.name").toLowerCase();
70+
if (os.startsWith("windows")) {
71+
testOnWindows();
72+
} else {
73+
testOnUnix();
74+
}
75+
}
76+
77+
@Override
78+
protected void testOnWindows() throws IOException {
79+
final String[] output = {
80+
"The file name must end with \"csv\"!",
81+
};
82+
ProcessBuilder builder =
83+
new ProcessBuilder(
84+
"cmd.exe",
85+
"/c",
86+
toolsPath + File.separator + "import-schema.bat",
87+
"-h",
88+
ip,
89+
"-p",
90+
port,
91+
"-u",
92+
"root",
93+
"-pw",
94+
"root",
95+
"-s",
96+
"./",
97+
"&",
98+
"exit",
99+
"%^errorlevel%");
100+
builder.environment().put("IOTDB_HOME", homePath);
101+
testOutput(builder, output, 0);
102+
}
103+
104+
@Override
105+
protected void testOnUnix() throws IOException {
106+
final String[] output = {
107+
"The file name must end with \"csv\"!",
108+
};
109+
ProcessBuilder builder =
110+
new ProcessBuilder(
111+
"bash",
112+
toolsPath + File.separator + "import-schema.sh",
113+
"-h",
114+
ip,
115+
"-p",
116+
port,
117+
"-u",
118+
"root",
119+
"-pw",
120+
"root",
121+
"-s",
122+
"./");
123+
builder.environment().put("IOTDB_HOME", homePath);
124+
testOutput(builder, output, 0);
125+
}
126+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@REM
2+
@REM Licensed to the Apache Software Foundation (ASF) under one
3+
@REM or more contributor license agreements. See the NOTICE file
4+
@REM distributed with this work for additional information
5+
@REM regarding copyright ownership. The ASF licenses this file
6+
@REM to you under the Apache License, Version 2.0 (the
7+
@REM "License"); you may not use this file except in compliance
8+
@REM with the License. You may obtain a copy of the License at
9+
@REM
10+
@REM http://www.apache.org/licenses/LICENSE-2.0
11+
@REM
12+
@REM Unless required by applicable law or agreed to in writing,
13+
@REM software distributed under the License is distributed on an
14+
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
@REM KIND, either express or implied. See the License for the
16+
@REM specific language governing permissions and limitations
17+
@REM under the License.
18+
@REM
19+
20+
@echo off
21+
22+
title IoTDB Export
23+
24+
echo ````````````````````````````````````````````````
25+
echo Starting IoTDB Client Export Schema Script
26+
echo ````````````````````````````````````````````````
27+
28+
if "%OS%" == "Windows_NT" setlocal
29+
30+
pushd %~dp0..
31+
if NOT DEFINED IOTDB_HOME set IOTDB_HOME=%CD%
32+
popd
33+
34+
if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.tool.ExportSchema
35+
if NOT DEFINED JAVA_HOME goto :err
36+
37+
@REM -----------------------------------------------------------------------------
38+
@REM JVM Opts we'll use in legacy run or installation
39+
set JAVA_OPTS=-ea^
40+
-DIOTDB_HOME="%IOTDB_HOME%"
41+
42+
@REM ***** CLASSPATH library setting *****
43+
if EXIST "%IOTDB_HOME%\lib" (set CLASSPATH="%IOTDB_HOME%\lib\*") else set CLASSPATH="%IOTDB_HOME%\..\lib\*"
44+
45+
REM -----------------------------------------------------------------------------
46+
47+
"%JAVA_HOME%\bin\java" -DIOTDB_HOME="%IOTDB_HOME%" %JAVA_OPTS% -cp %CLASSPATH% %MAIN_CLASS% %*
48+
set ret_code=%ERRORLEVEL%
49+
goto finally
50+
51+
52+
:err
53+
echo JAVA_HOME environment variable must be set!
54+
set ret_code=1
55+
pause
56+
57+
@REM -----------------------------------------------------------------------------
58+
:finally
59+
60+
ENDLOCAL
61+
62+
EXIT /B %ret_code%
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
echo ------------------------------------------
22+
echo Starting IoTDB Client Export Schema Script
23+
echo ------------------------------------------
24+
25+
if [ -z "${IOTDB_INCLUDE}" ]; then
26+
#do nothing
27+
:
28+
elif [ -r "$IOTDB_INCLUDE" ]; then
29+
. "$IOTDB_INCLUDE"
30+
fi
31+
32+
if [ -z "${IOTDB_HOME}" ]; then
33+
export IOTDB_HOME="$(cd "`dirname "$0"`"/..; pwd)"
34+
fi
35+
36+
if [ -n "$JAVA_HOME" ]; then
37+
for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
38+
if [ -x "$java" ]; then
39+
JAVA="$java"
40+
break
41+
fi
42+
done
43+
else
44+
JAVA=java
45+
fi
46+
47+
if [ -z $JAVA ] ; then
48+
echo Unable to find java executable. Check JAVA_HOME and PATH environment variables. > /dev/stderr
49+
exit 1;
50+
fi
51+
52+
CLASSPATH=${IOTDB_HOME}/lib/*
53+
54+
MAIN_CLASS=org.apache.iotdb.tool.ExportSchema
55+
56+
"$JAVA" -DIOTDB_HOME=${IOTDB_HOME} -cp "$CLASSPATH" "$MAIN_CLASS" "$@"
57+
exit $?

0 commit comments

Comments
 (0)