我正在处理一个更复杂的查询,但我的问题已简化为简单的问题。我希望有人能帮助我。
给出下表(请参阅下面的HOSTED_APPS_METADATA_UUID)
!tables
+------------+--------------+-------------------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+-----------+
| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | INDEX_STATE | IMMUTABLE_ROWS | SALT_BUCKETS | MULTI_TEN |
+------------+--------------+-------------------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+-----------+
| | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false |
| | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false |
| | SYSTEM | LOG | SYSTEM TABLE | | | | | | true | 32 | false |
| | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | 2 | false |
| | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false |
| | | CONTAINER_METRICS | TABLE | | | | | | true | null | false |
| | | HOSTED_APPS_METADATA_UUID | TABLE | | | | | | false | null | false |
| | | INSTANCE_HOST_METADATA | TABLE | | | | | | false | null | false |
| | | METRICS_METADATA_UUID | TABLE | | | | | | false | null | false |
| | | METRIC_AGGREGATE_DAILY_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_AGGREGATE_HOURLY_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_AGGREGATE_MINUTE_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_AGGREGATE_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_RECORD_DAILY_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_RECORD_HOURLY_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_RECORD_MINUTE_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_RECORD_UUID | TABLE | | | | | | true | null | false |
| | | METRIC_TRANSIENT | TABLE | | | | | | true | null | false |
+------------+--------------+-------------------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+-----------+
!describe HOSTED_APPS_METADATA_UUID
+------------+--------------+----------------------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----+
| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME | COLUMN_SIZE | BUFFER_LENGTH | DECIMAL_DIGITS | NUM_PREC_RADIX | NULLABLE | REMARKS | COLUMN_DEF | SQ |
+------------+--------------+----------------------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----+
| | | HOSTED_APPS_METADATA_UUID | HOSTNAME | 12 | VARCHAR | null | null | null | null | 0 | | | nu |
| | | HOSTED_APPS_METADATA_UUID | UUID | -2 | BINARY | 4 | null | null | null | 1 | | | nu |
| | | HOSTED_APPS_METADATA_UUID | APP_IDS | 12 | VARCHAR | null | null | null | null | 1 | | | nu |
+------------+--------------+----------------------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----+
There is a column called UUID of BINARY type.
I'm using sqlline.py to issue a query. Here's a simple one:
select * from HOSTED_APPS_METADATA_UUID;
+-----------------------------------------------------------------+--------------+----------------------------------------------------------------------------------------------------------------------------+
| HOSTNAME | UUID | APP_IDS |
+-----------------------------------------------------------------+--------------+----------------------------------------------------------------------------------------------------------------------------+
| hn0-gjshdi.5uu4vnfquqlelgdmoqysq1y3jg.cx.internal.cloudapp.net | [B@66e8997c | hiveserver2,hivemetastore,resourcemanager,historyserver,HOST,applicationhistoryserver,jobhistoryserver,namenode,ams-hbase |
| hn1-gjshdi.5uu4vnfquqlelgdmoqysq1y3jg.cx.internal.cloudapp.net | [B@6f0cb5a1 | hiveserver2,hivemetastore,resourcemanager,historyserver,HOST,namenode |
| wn0-gjshdi.5uu4vnfquqlelgdmoqysq1y3jg.cx.internal.cloudapp.net | [B@1b29d52b | datanode,HOST,nodemanager |
| zk0-gjshdi.5uu4vnfquqlelgdmoqysq1y3jg.cx.internal.cloudapp.net | [B@47547132 | journalnode,HOST |
| zk1-gjshdi.5uu4vnfquqlelgdmoqysq1y3jg.cx.internal.cloudapp.net | [B@655523dd | journalnode,HOST |
| zk3-gjshdi.5uu4vnfquqlelgdmoqysq1y3jg.cx.internal.cloudapp.net | [B@6f7e336b | journalnode,HOST |
+-----------------------------------------------------------------+--------------+----------------------------------------------------------------------------------------------------------------------------+
如何设置查询来过滤 UUID 值之一?
例如,我想仅从上面的输出中选择第一行,但不确定下面的 uuid 值的格式。我认为语法上有问题:
我尝试了多种变化,这让我发疯:)
select * from HOSTED_APPS_METADATA_UUID where UUID = [B@66e8997c;
...导致以下错误:
Error: ERROR 602 (42P00): Syntax error. Missing "LPAREN" at line 1, column 47. (state=42P00,code=602)
org.apache.phoenix.exception.PhoenixParserException: ERROR 602 (42P00): Syntax error. Missing "LPAREN" at line 1, column 47.
at org.apache.phoenix.exception.PhoenixParserException.newException(PhoenixParserException.java:33)
at org.apache.phoenix.parse.SQLParser.parseStatement(SQLParser.java:111)
at org.apache.phoenix.jdbc.PhoenixStatement$PhoenixStatementParser.parseStatement(PhoenixStatement.java:1644)
at org.apache.phoenix.jdbc.PhoenixStatement.parseStatement(PhoenixStatement.java:1727)
at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1819)
at sqlline.Commands.execute(Commands.java:822)
at sqlline.Commands.sql(Commands.java:732)
at sqlline.SqlLine.dispatch(SqlLine.java:813)
at sqlline.SqlLine.begin(SqlLine.java:686)
at sqlline.SqlLine.start(SqlLine.java:398)
at sqlline.SqlLine.main(SqlLine.java:291)
Caused by: MissingTokenException(inserted [@-1,0:0='<missing LPAREN>',<100>,1:46] at UUID)
at org.apache.phoenix.parse.PhoenixSQLParser.recoverFromMismatchedToken(PhoenixSQLParser.java:374)
at org.apache.phoenix.shaded.org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)
at org.apache.phoenix.parse.PhoenixSQLParser.not_expression(PhoenixSQLParser.java:7851)
at org.apache.phoenix.parse.PhoenixSQLParser.and_expression(PhoenixSQLParser.java:7671)
at org.apache.phoenix.parse.PhoenixSQLParser.or_expression(PhoenixSQLParser.java:7608)
at org.apache.phoenix.parse.PhoenixSQLParser.expression(PhoenixSQLParser.java:7573)
at org.apache.phoenix.parse.PhoenixSQLParser.single_select(PhoenixSQLParser.java:5192)
at org.apache.phoenix.parse.PhoenixSQLParser.unioned_selects(PhoenixSQLParser.java:5274)
at org.apache.phoenix.parse.PhoenixSQLParser.select_node(PhoenixSQLParser.java:5340)
at org.apache.phoenix.parse.PhoenixSQLParser.oneStatement(PhoenixSQLParser.java:841)
at org.apache.phoenix.parse.PhoenixSQLParser.statement(PhoenixSQLParser.java:524)
at org.apache.phoenix.parse.SQLParser.parseStatement(SQLParser.java:108)
... 9 more
更广阔的前景。我正在尝试从另一个应用程序获取日志输出并在 sqlline.py 中创建一个独立的查询。
以下是此日志记录输出的示例,其中 ?替换为以下值:
SELECT UUID, SERVER_TIME, METRIC_SUM, HOSTS_COUNT, METRIC_MAX, METRIC_MIN FROM METRIC_AGGREGATE_UUID WHERE (UUID IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) AND SERVER_TIME >= ? AND SERVER_TIME < ? ORDER BY UUID, SERVER_TIME, condition => Condition{uuids=[[B@2948f779, [B@3ca87491, [B@6702e8f, [B@7a907628, [B@148da53c, [B@6bfe57c0, [B@6cfd0866, [B@15a512e7, [B@6c78f12a, [B@75a1eb32, [B@719b73d8, [B@4c946526, [B@67ce3c3f, [B@1dcca38f, [B@3763165d], appId='NODEMANAGER', instanceId='null', startTime=1675461194000, endTime=1675461510000, limit=null, grouped=true, orderBy=[], noLimit=true}
上面,基本查询是:
SELECT UUID, SERVER_TIME, METRIC_SUM, HOSTS_COUNT, METRIC_MAX, METRIC_MIN FROM METRIC_AGGREGATE_UUID WHERE (UUID IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) AND SERVER_TIME >= ? AND SERVER_TIME < ? ORDER BY UUID, SERVER_TIME
您可以看到后面的15 UUID参数。我似乎无法弄清楚如何使用这些 uuid 提供查询,并且每当我在查询中的任何位置尝试 UUID 时,我都会不断收到相同的 LPAREN 错误。
驱动程序版本 -> PhoenixEmbeddedDriver(版本 5.0)
任何提示都非常感谢!
多玩玩这个,我假设每个 UUID 周围都需要单引号,类似于下面。我不再收到 LPARAM 错误 - 但预期的数据似乎不存在。可能还漏掉了其他东西。
SELECT UUID, SERVER_TIME, METRIC_SUM, METRIC_MAX, METRIC_MIN, METRIC_COUNT FROM METRIC_RECORD_HOURLY_UUID WHERE (UUID IN ('[B@70242f38')) ORDER BY UUID, SERVER_TIME;
+-------+--------------+-------------+-------------+-------------+---------------+
| UUID | SERVER_TIME | METRIC_SUM | METRIC_MAX | METRIC_MIN | METRIC_COUNT |
+-------+--------------+-------------+-------------+-------------+---------------+
+-------+--------------+-------------+-------------+-------------+---------------+
No rows selected (0.167 seconds)
我查看了凤凰用户论坛并收到了以下答案。 这解释了为什么一旦我使用单引号克服了 LPARAM 错误,我的查询就不会从 sqlline.py 返回任何数据。
Phoenix 仅添加了在中指定二进制文字的功能 PHOENIX-6764,但尚未在任何发布的版本中提供。 目前在查询中指定二进制字符串的唯一方法是通过 JDBC 中的PreparedStatment.setBytes()。无法指定 它们直接在查询文本中。另外,[B@4632cfc 看起来根本不 就像一个有效的 UUID,更像是一个指向生成的 java 对象的指针 通过.toString(),所以你也可能会遇到插入问题。
我使用此查询来查明服务的某些指标是否已收集并保存到 ams hbase 并且似乎有效:
0: jdbc:phoenix:localhost:2181/ams-hbase-unse> select * from METRIC_AGGREGATE_UUID where UUID in (select UUID from METRICS_METADATA_UUID where APP_ID='datanode' and METRIC_NAME='mem_free'); +------------+------------------------+-------------------- ---+-------------+----------------------+--------- -------------+ | UUID |服务器时间 |度量总和 | HOSTS_COUNT | 主机公制最大 |公制_最小值 | +------------+------------------------+-------------------- ---+-------------+----------------------+--------- -------------+ | [B@164dea80 | 1699082940000 | 1.203734E7 | 1 | 1.203734E7 | 1.203734E7 | | [B@4392362c | 1699082970000 | 1.203734E7 | 1 | 1.203734E7 | 1.203734E7 | | [B@338a4c61 | 1699083000000 | 1.203734E7 | 1 | 1.203734E7 | 1.203734E7 | | [B@839755f | 1699083030000 | 1.203734E7 | 1 | 1.203734E7 | 1.203734E7 | | [B@71d99732 | 1699083060000 | 1.2034292E7 | 1 | 1.2034292E7 | 1.2034292E7 |