Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

没有TableData这个类,解析的结果想要get到某个属性,需要先强转到对应类型 #9

Open
Kiss736921 opened this issue Nov 27, 2023 · 8 comments

Comments

@Kiss736921
Copy link

libinsong那个版本里有个TableData的类
然后每次强转一下:
TableData tableData = (TableData) statement
tableData.get就能获取语句的类型,以及输入表或者输出表,以及其他信息,咱们这个里面能加一个这样的拥有所以属性的类吗,然后强转一下就能很方便的get了

image

类似于这样,谢谢!

@melin
Copy link
Owner

melin commented Nov 27, 2023

@Kiss736921
Copy link
Author

API 变化了,TableData 已经不存在了。具体参考一下Test: https://github.com/melin/superior-sql-parser/blob/master/superior-spark-parser/src/test/kotlin/io/github/melin/superior/parser/spark/SparkSqlParserTest.kt

ok,那就是解析出来以后判断一下类型,然后再转换一下,才能获取里面的属性,对吧,类似于这样

  public static void main(String[] args) {
        String sql = "insert into ddd.aaa select ip, name from ccc.bbb";
        Statement statement = SparkSqlHelper.parseStatement(sql);
        if (statement instanceof InsertTable) {
            InsertTable statement1 = (InsertTable) statement;
            System.out.println(statement1.getInputTables().get(0).getTableName());
            System.out.println(statement1.getOutputTables());
        }
    }

然后顺便问一下,这个语句类型是不是不好支持:not support InsertMode.OVERWRITE_HIVE_DIR
insert overwrite directory 'hdfs://xxx' row format delimited fields terminated by '\t'
select a, b from test
或者带with的这种
with test as (
    select a, b from aaa
)
insert overwrite directory 'hdfs://xxx' row format delimited fields terminated by '\t'
select a, b from test

这种sql我看源码解析的时候都抛不支持的异常了,这种sql想解析出查了哪些表好实现不,大佬指导下,谢谢!

@melin
Copy link
Owner

melin commented Nov 27, 2023

1、如你所说的使用
2、可以支持的,这两天添加一下。

@Kiss736921
Copy link
Author

Kiss736921 commented Nov 27, 2023

1、如你所说的使用 2、可以支持的,这两天添加一下。

第二个如果能支持那太感谢啦,多谢大佬

ea4a643

@Kiss736921
Copy link
Author

@melin
编译报错

`A fatal error has been detected by the Java Runtime Environment:
SIGSEGV (0xb) at pc=0x0000000109f1c718, pid=93359, tid=0x0000000000002703
JRE version: Java(TM) SE Runtime Environment (8.0_202-b08) (build 1.8.0_202-b08)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.202-b08 mixed mode bsd-amd64 compressed oops)
Problematic frame:
V [libjvm.dylib+0x4ec718] SharedRuntime::resolve_sub_helper(JavaThread*, bool, bool, Thread*)+0x360
Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
An error report file with more information is saved as:
/Users/admin/IdeaProjects/alex/superior-sql-parser/hs_err_pid93359.log
Compiled method (c2) 44208 24923 ! 4 com.intellij.util.containers.ConcurrentIntObjectHashMap::tabAt (33 bytes)
total in heap [0x00000001116db990,0x00000001116dbcd0] = 832
relocation [0x00000001116dbab8,0x00000001116dbad8] = 32
main code [0x00000001116dbae0,0x00000001116dbb80] = 160
stub code [0x00000001116dbb80,0x00000001116dbba8] = 40
oops [0x00000001116dbba8,0x00000001116dbbc8] = 32
metadata [0x00000001116dbbc8,0x00000001116dbbf8] = 48
scopes data [0x00000001116dbbf8,0x00000001116dbc60] = 104
scopes pcs [0x00000001116dbc60,0x00000001116dbcb0] = 80
dependencies [0x00000001116dbcb0,0x00000001116dbcb8] = 8
handler table [0x00000001116dbcb8,0x00000001116dbcd0] = 24
Compiled method (nm) 44212 4516 n 0 java.lang.invoke.MethodHandle::linkToSpecial(LLJL)L (native)
total in heap [0x000000010c41ab10,0x000000010c41ac58] = 328
relocation [0x000000010c41ac38,0x000000010c41ac40] = 8
main code [0x000000010c41ac40,0x000000010c41ac58] = 24

If you would like to submit a bug report, please visit:
http://bugreport.java.com/bugreport/crash.jsp

[1] 93359 abort mvn clean package -DskipTests
`

@Kiss736921
Copy link
Author

@melin
大佬,我测了下上面的with语句,解析是解析出来了,目标路径也有,但是outputTables没有值,就是没有获取到with里面真正查询的表,这个能支持吗

@melin
Copy link
Owner

melin commented Nov 28, 2023

@melin 大佬,我测了下上面的with语句,解析是解析出来了,目标路径也有,但是outputTables没有值,就是没有获取到with里面真正查询的表,这个能支持吗

更新了,再试试

@Kiss736921
Copy link
Author

@melin 大佬,我测了下上面的with语句,解析是解析出来了,目标路径也有,但是outputTables没有值,就是没有获取到with里面真正查询的表,这个能支持吗

更新了,再试试

可以了可以了,太感谢啦,感谢大佬!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants