I'm newbie of Impala, i need to create table with select resultset, also, this sql is run in Java using JDBC, see my below query:
create table if not exists my_temp_table as select
41 as rule_id,49 as record_id,
(select count(1) as val from dirty_table where msg regexp '^[1]([3-9])[0-9]{9}$' )/(select count(1) from dirty_table);
I need to create table my_temp_table and insert data into this table, this is one SQL that i need to run. But it runs failed and gives errer as below:
[HY000][500051] [Cloudera][ImpalaJDBCDriver](500051) ERROR processing query/statement. Error Code: 0, SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:HY000, errorMessage:ParseException: Syntax error
After checking, i know Impala doesn't support SELECT clause subquery, we can only use subquery
in FROM or WHERE clause, see Impala docs: https://impala.apache.org/docs/build/html/topics/impala_subqueries.html.
So for this question how can i do to solve this problem.
My thought:
- update sql to let it execute, I tried
WITHlike below sql, it works but can't be used inCREATE TABLE ... AS ....
WITH q1 AS (
select count(1) as val from dirty_table where msg regexp '^[1]([3-9])[0-9]{9}$'
),
q2 AS (
select count(1) val2 from dirty_table
)
SELECT 100 * q1.val / q2.val2 result
FROM q1, q2
- or, is there any statement like
BEGIN ... ENDin MySQL or Oracle, then i can run this sql separately.