Skip to content

Commit bd20c1c

Browse files
fix: log dependencies and quote sql
1 parent a1dcb7a commit bd20c1c

5 files changed

Lines changed: 58 additions & 9 deletions

File tree

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ addtable t1 a int, b int64
4343

4444
# validate in online request mode
4545
valreq select count(*) over w1 from t1 window w1 as (partition by a order by b rows between unbounded preceding and current row);
46+
47+
# When there are single quotes in SQL (currently double quotes are not supported, only single quotes can be used), please enclose them in double quotes to avoid parsing missing quotes.
48+
valreq "select * from t1 join t2 on t2.b='abc'"
4649
```
4750
If the test fails, it will print the SQL compilation error. If it passes, it will print `validate * success`. The entire process takes place in a virtual environment, without concerns about resource usage after table creation or any side effects. Any SQL that passes validation through `valreq` will definitely be deployable in a real cluster.
4851

@@ -181,7 +184,7 @@ Note that if a table already exists, the creation of a new table will replace th
181184

182185
If you want to create tables without redundant indexes, you can use `genddl` to generate ddl from the query SQL.
183186

184-
Note that method `genDDL` in `openmldb-jdbc` does not support multiple databases yet, so we can't use this method to parse SQLs that have multiple dbs.
187+
Note that the `genDDL` method in `openmldb-jdbc` does not yet support multiple databases. Therefore, we cannot use this method to parse SQL statements that involve multiple databases. When there are single quotes in the SQL (double quotes are not supported at the moment, only single quotes), please enclose the SQL in double quotes to avoid missing quotes during parsing. For example, use `genddl "select * from t1 join t2 on t2.c1 == '123';"`.
185188

186189
- Example1
187190
```
@@ -265,3 +268,14 @@ t1;
265268
### CLI Framework
266269

267270
We use `cliche` for the CLI interface. See [Manual](https://code.google.com/archive/p/cliche/wikis/Manual.wiki) and [source](https://github.com/budhash/cliche).
271+
272+
Due to the simplicity of the framework, when quotation marks are required in the SQL, only single quotation marks can be used, and the entire SQL must be enclosed in double quotation marks. Otherwise, the parsing will discard the double quotation marks in the SQL.
273+
274+
### Debugging
275+
276+
If you encounter any issues during usage, you can specify `log4j.properties` using `-Dlog4j.configuration=`. By default, the log level is set to WARN, but you can change it to print INFO and above logs to obtain more runtime information.
277+
278+
To test in the project:
279+
```bash
280+
java -jar target/emulator-1.1-SNAPSHOT.jar -Dlog4j.configuration=./src/test/resources/log4j.properties
281+
```

README_zh.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ addtable t1 a int, b int64
3131
你可以使用`val``valreq`分别进行在线批模式和在线请求模式(即服务部署上线)的OpenMLDB SQL验证。例如,我们测试一个SQL是否能被`DEPLOY`上线,使用`valreq`命令:
3232

3333
```sql
34-
# table creations - t/addtable: create table
34+
# table 创建 - t/addtable: create table
3535
addtable t1 a int, b int64
36+
addtable t2 a int, b string
3637

37-
# validate in online request mode
38+
# 在线请求模式下验证SQL
3839
valreq select count(*) over w1 from t1 window w1 as (partition by a order by b rows between unbounded preceding and current row);
40+
# SQL中存在单引号时(目前不支持双引号,只能使用单引号),请用双引号括起来,避免解析遗漏引号
41+
valreq "select * from t1 join t2 on t2.b='abc'"
3942
```
4043

4144
如果测试不通过,将打印SQL编译错误;通过则打印`validate * success`。整个过程在虚拟环境中,无需担心建表后的资源占用,也没有任何副作用。只要`valreq`验证通过的 SQL,则一定能在真实集群中上线。
@@ -172,7 +175,7 @@ Emulator使用`openmldb-jdbc`进行验证,目前支持的OpenMLDB版本为:
172175

173176
#### `genddl <sql>`
174177

175-
可以帮助用户根据SQL直接生成最佳索引的建表语句,避免冗余索引(目前仅支持单数据库)。
178+
可以帮助用户根据SQL直接生成最佳索引的建表语句,避免冗余索引(目前仅支持单数据库)。SQL中存在单引号时(目前不支持双引号,只能使用单引号),请用双引号括起来,避免解析遗漏引号,例如,`genddl "select * from t1 join t2 on t2.c1 == '123';"`
176179

177180
- 范例1
178181
```
@@ -255,3 +258,14 @@ t1;
255258
### CLI框架
256259

257260
我们使用`cliche`作为CLI框架,详见[操作手册](https://code.google.com/archive/p/cliche/wikis/Manual.wiki)[source](https://github.com/budhash/cliche)
261+
262+
由于框架简单,SQL中必须存在引号时,只能使用单引号,并将整个SQL用双引号括起来。否则,解析会丢掉SQL中的双引号。
263+
264+
### 调试
265+
266+
使用过程中如果出现问题,可以通过`-Dlog4j.configuration=`指定`log4j.properties`,默认是WARN日志,可以改为打印INFO及以上的日志,能获取更多运行信息。
267+
268+
在项目中测试:
269+
```bash
270+
java -jar target/emulator-1.1-SNAPSHOT.jar -Dlog4j.configuration=./src/test/resources/log4j.properties
271+
```

pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@
4545
<artifactId>snakeyaml</artifactId>
4646
<version>2.2</version>
4747
</dependency>
48+
<dependency>
49+
<groupId>org.projectlombok</groupId>
50+
<artifactId>lombok</artifactId>
51+
<version>1.18.22</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.slf4j</groupId>
55+
<artifactId>slf4j-log4j12</artifactId>
56+
<version>2.0.0-alpha1</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.slf4j</groupId>
60+
<artifactId>slf4j-simple</artifactId>
61+
<version>1.7.21</version>
62+
</dependency>
4863
</dependencies>
4964

5065
<build>

src/main/java/com/openmldb/emulator/App.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ private boolean toydbSupport() {
227227
public void genddl(@Param(name = "sql", description = "deployment sql") String... sqlParts)
228228
throws SQLException {
229229
String sql = Joiner.on(" ").join(sqlParts);
230+
log.info("gen ddl: {}", sql);
230231
List<String> ddl = SqlClusterExecutor.genDDL(sql, schemaMap);
231232
System.out.println(Joiner.on("\n").join(ddl));
232233
}

src/test/java/com/openmldb/emulator/AppTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.openmldb.emulator;
22

3-
import static org.junit.Assert.assertThat;
43
import static org.junit.Assert.assertTrue;
54

65
import java.io.BufferedReader;
@@ -12,10 +11,6 @@
1211

1312
import com.google.common.base.Charsets;
1413
import com.google.common.io.CharSource;
15-
import com.google.common.io.CharStreams;
16-
import com.google.common.io.Resources;
17-
import com.openmldb.emulator.App;
18-
1914
import asg.cliche.CLIException;
2015
import asg.cliche.Shell;
2116
import asg.cliche.ShellFactory;
@@ -79,4 +74,14 @@ public void testYamlCases() throws SQLException, IOException {
7974
App app = new App();
8075
app.run(com.google.common.io.Resources.getResource("case.yaml").getFile());
8176
}
77+
78+
@Test
79+
public void testGenddl() throws SQLException {
80+
App app = new App();
81+
app.addtable("t1", "c1 int, c2 string, c3 string, c4 string");
82+
app.addtable("t2", "c1 int, c2 string, c3 string, c4 string");
83+
app.genddl("select * from t1 last join t2 t22 on t1.c1=t22.c1 and t1.c2=t22.c2 and t1.c3=t22.c3 and t22.c4='abc'");
84+
app.genddl("select * from t1 last join t2 t22 on t1.c1=t22.c1 and t1.c2=t22.c2 and t1.c3=t22.c3 and t22.c4=abc");
85+
86+
}
8287
}

0 commit comments

Comments
 (0)