Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/TreeToTableView' into device_view
Browse files Browse the repository at this point in the history
  • Loading branch information
Caideyipi committed Dec 25, 2024
2 parents b9ad96c + db1bd9b commit c614034
Show file tree
Hide file tree
Showing 37 changed files with 3,690 additions and 254 deletions.
33 changes: 18 additions & 15 deletions docker/src/main/DockerCompose/replace-conf-from-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,36 @@
conf_path=${IOTDB_HOME}/conf
target_files="iotdb-system.properties"

function process_single(){
local key_value="$1"
local filename=$2
local key=$(echo $key_value|cut -d = -f1)
local line=$(grep -ni "${key}=" ${filename})
#echo "line=$line"
if [[ -n "${line}" ]]; then
function process_single() {
local key_value="$1"
local filename=$2
local key=$(echo $key_value | cut -d = -f1)
local line=$(grep -ni "${key}=" ${filename})
#echo "line=$line"
if [[ -n "${line}" ]]; then
echo "update $key $filename"
local line_no=$(echo $line|cut -d : -f1)
local content=$(echo $line|cut -d : -f2)
if [[ "${content:0:1}" != "#" ]]; then
local line_no=$(echo $line | cut -d : -f1)
local content=$(echo $line | cut -d : -f2)
if [[ "${content:0:1}" != "#" ]]; then
sed -i "${line_no}d" ${filename}
fi
sed -i "${line_no} i${key_value}" ${filename}
fi
else
echo "append $key to $filename"

echo "${key_value}" >>"${filename}"
fi
}

function replace_configs(){
function replace_configs() {
for v in $(env); do
if [[ "${v}" =~ "=" && "${v}" =~ "_" && ! "${v}" =~ "JAVA_" ]]; then
# echo "###### $v ####"
# echo "###### $v ####"
for f in ${target_files}; do
process_single $v ${conf_path}/$f
process_single $v ${conf_path}/$f
done
fi
done
}

replace_configs

Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/*
* 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;

import com.google.gson.JsonParser;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class TableHttpExample {

private static final String UTF8 = "utf-8";

private String getAuthorization(String username, String password) {
return Base64.getEncoder()
.encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
}

public static void main(String[] args) {
TableHttpExample httpExample = new TableHttpExample();
httpExample.ping();
httpExample.createDatabase();
httpExample.createTable();
httpExample.nonQuery();
httpExample.insertTablet();
httpExample.query();
}

public void ping() {
CloseableHttpClient httpClient = SSLClient.getInstance().getHttpClient();
HttpGet httpGet = new HttpGet("http://127.0.0.1:18080/ping");
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpGet);
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, UTF8);
String result = JsonParser.parseString(message).getAsJsonObject().toString();
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
System.out.println("The ping rest api failed");
} finally {
try {
httpClient.close();
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Http Client close error");
}
}
}

private HttpPost getHttpPost(String url) {
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-type", "application/json; charset=utf-8");
httpPost.setHeader("Accept", "application/json");
String authorization = getAuthorization("root", "root");
httpPost.setHeader("Authorization", authorization);
return httpPost;
}

public void insertTablet() {
CloseableHttpClient httpClient = SSLClient.getInstance().getHttpClient();
CloseableHttpResponse response = null;
try {
HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/table/v1/insertTablet");
String json =
"{\"database\":\"test\",\"column_types\":[\"ID\",\"ATTRIBUTE\",\"MEASUREMENT\"],\"timestamps\":[1635232143960,1635232153960,1635232163960,1635232173960,1635232183960],\"column_names\":[\"id1\",\"t1\",\"s1\"],\"data_types\":[\"STRING\",\"STRING\",\"FLOAT\"],\"values\":[[\"a11\",\"true\",11333],[\"a11\",\"false\",22333],[\"a13\",\"false1\",23333],[\"a14\",\"false2\",24],[\"a15\",\"false3\",25]],\"table\":\"sg211\"}";
httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, UTF8);
String result = JsonParser.parseString(message).getAsJsonObject().toString();
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
System.out.println("The insertTablet rest api failed");
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Response close error");
}
}
}

public void nonQuery() {
CloseableHttpClient httpClient = SSLClient.getInstance().getHttpClient();
CloseableHttpResponse response = null;
try {
HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/table/v1/nonQuery");
String sql =
"{\"database\":\"test\",\"sql\":\"INSERT INTO sg211(time, id1, s1) values(100, 'd1', 0)\"}";
httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, UTF8);
System.out.println(JsonParser.parseString(message).getAsJsonObject().toString());
} catch (IOException e) {
e.printStackTrace();
System.out.println("The non query rest api failed");
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Response close error");
}
}
}

public void createDatabase() {
CloseableHttpClient httpClient = SSLClient.getInstance().getHttpClient();
CloseableHttpResponse response = null;
try {
HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/table/v1/nonQuery");
String sql = "{\"database\":\"\",\"sql\":\"create database if not exists test\"}";
httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, UTF8);
System.out.println(JsonParser.parseString(message).getAsJsonObject().toString());
} catch (IOException e) {
e.printStackTrace();
System.out.println("The non query rest api failed");
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Response close error");
}
}
}

public void createTable() {
CloseableHttpClient httpClient = SSLClient.getInstance().getHttpClient();
CloseableHttpResponse response = null;
try {
HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/table/v1/nonQuery");
String sql =
"{\"database\":\"test\",\"sql\":\"create table sg211 (id1 string id,t1 STRING ATTRIBUTE, s1 FLOAT measurement)\"}";
httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, UTF8);
System.out.println(JsonParser.parseString(message).getAsJsonObject().toString());
} catch (IOException e) {
e.printStackTrace();
System.out.println("create table failed");
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Response close error");
}
}
}

public void query() {
CloseableHttpClient httpClient = SSLClient.getInstance().getHttpClient();
CloseableHttpResponse response = null;
try {
HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/table/v1/query");
String sql = "{\"database\":\"test\",\"sql\":\"select * from sg211\"}";
httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, UTF8);
System.out.println(JsonParser.parseString(message).getAsJsonObject().toString());
} catch (IOException e) {
e.printStackTrace();
System.out.println("The query rest api failed");
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Response close error");
}
}
}
}
Loading

0 comments on commit c614034

Please sign in to comment.