aws athena & java - 在结构类型列中获取数据
Posted
技术标签:
【中文标题】aws athena & java - 在结构类型列中获取数据【英文标题】:aws athena & java - get data in struct type colomn 【发布时间】:2018-05-22 09:48:58 【问题描述】:我在 athena 中创建了一个表,用于映射 aws s3 存储桶中的一些数据。我有一个列,其类型是对象数组(结构)。
CREATE EXTERNAL TABLE traceroute (
af int,
dst_addr string,
dst_name string,
`timestamp` int,
type string,
result array< struct< hop:int,result:array<struct<rtt:int>>>>
...
我使用 JDBC 来获取结果:
Connection conn = new Tools().getConnection();
String selectTableSQL = "SELECT * FROM \"sampledb\".\"traceroute\" limit 1";
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(selectTableSQL);
while (rs.next())
// TODO
现在,我找不到如何获取结构类型的数据,例如 rtt 的值。
JDBC 是从嵌套数据中获取数据的正确选择吗?有什么帮助吗?
【问题讨论】:
【参考方案1】:我找到了如何做到这一点:使用 brackets [] 表示数组和 point 。对于结构。
例如,要获取结果的第一个元素和该结果的第二个元素的 rtt 值:
Connection conn = new Tools().getConnection();
String selectTableSQL = "SELECT result[1].result[2].rtt as rtt FROM \"sampledb\".\"traceroute\"";
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(selectTableSQL);
while (rs.next())
// TODO
System.out.println(rs.getInt("rtt"));
但是,我无法在一个变量中获取所有数组的内容以进行循环。我将数组作为 VarCharValue,例如:
[hop=1, result=[from=192.168.178.1, rtt=1.13, ttl=64, x=null, from=192.168.178.1, rtt=0.973, ttl=64, x=null, from=192.168.178.1, rtt=1.097, ttl=64, x=null], hop=2, result=[from=94.252.127.254, rtt=9.381, ttl=63, x=null, from=94.252.127.254, rtt=1.83, ttl=63, x=null, from=94.252.127.254, rtt=9.002, ttl=63, x=null], hop=3, result=[from=10.13.69.102, rtt=9.024, ttl=62, x=null, from=10.13.69.102, rtt=9.248, ttl=62, x=null, from=10.13.69.102, rtt=8.846, ttl=62, x=null], hop=4, result=[from=212.66.71.121, rtt=2.976, ttl=252, x=null, from=212.66.71.121, rtt=7.888, ttl=252, x=null, from=212.66.71.121, rtt=9.295, ttl=252, x=null], hop=5, result=[from=81.20.77.45, rtt=8.541, ttl=251, x=null, from=81.20.77.45, rtt=8.604, ttl=251, x=null, from=81.20.77.45, rtt=8.857, ttl=251, x=null], hop=6, result=[from=129.250.4.56, rtt=15.373, ttl=250, x=null, from=129.250.4.56, rtt=8.978, ttl=250, x=null, from=129.250.4.56, rtt=20.782, ttl=250, x=null], hop=7, result=[from=129.250.6.162, rtt=99.887, ttl=249, x=null, from=129.250.6.162, rtt=97.941, ttl=249, x=null, from=129.250.6.162, rtt=98.485, ttl=249, x=null], hop=8, result=[from=129.250.2.139, rtt=129.513, ttl=248, x=null, from=129.250.2.139, rtt=121.402, ttl=248, x=null, from=129.250.2.139, rtt=142.645, ttl=248, x=null], hop=9, result=[from=129.250.4.214, rtt=116.211, ttl=247, x=null, from=129.250.4.214, rtt=117.243, ttl=247, x=null, from=129.250.4.214, rtt=118.314, ttl=247, x=null], hop=10, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*], hop=11, result=[from=143.56.224.122, rtt=139.849, ttl=54, x=null, from=143.56.224.122, rtt=136.935, ttl=54, x=null, from=143.56.224.122, rtt=137.629, ttl=54, x=null], hop=12, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*], hop=13, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=140.6.0.3, rtt=136.145, ttl=52, x=null], hop=14, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*], hop=15, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*], hop=16, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*], hop=17, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*], hop=18, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*], hop=255, result=[from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*, from=null, rtt=null, ttl=null, x=*]]
【讨论】:
以上是关于aws athena & java - 在结构类型列中获取数据的主要内容,如果未能解决你的问题,请参考以下文章
使用 AWS Glue Scala 查询 Athena(添加分区)