I’m trying to execute SQL query on Polars dataframes using SQLContext and below is my code:
<code> ctx = pl.SQLContext().register_many(
{"tbl1": df_source, "tbl2": df_reference})
src_df = ctx.execute(pl_sql_query, eager=True)
</code>
<code> ctx = pl.SQLContext().register_many(
{"tbl1": df_source, "tbl2": df_reference})
src_df = ctx.execute(pl_sql_query, eager=True)
</code>
ctx = pl.SQLContext().register_many(
{"tbl1": df_source, "tbl2": df_reference})
src_df = ctx.execute(pl_sql_query, eager=True)
Here the schema of df_source contains a column named json_message of type Struct with Key Value pairs i.e.,
<code>('json_message', Struct({'id': Int64, 'name': String, 'age': Int64, 'dob': String}))
</code>
<code>('json_message', Struct({'id': Int64, 'name': String, 'age': Int64, 'dob': String}))
</code>
('json_message', Struct({'id': Int64, 'name': String, 'age': Int64, 'dob': String}))
My sql query to access the struct field is:
<code>pl_sql_query =
"select json_message.id as id, json_message.name as name
from tbl1
where json_message.id in (select id from tbl2)"
</code>
<code>pl_sql_query =
"select json_message.id as id, json_message.name as name
from tbl1
where json_message.id in (select id from tbl2)"
</code>
pl_sql_query =
"select json_message.id as id, json_message.name as name
from tbl1
where json_message.id in (select id from tbl2)"
When i execute this query, i’m getting an exception no table or alias named ‘json_message’ found
Not sure how exactly we need to access the struct field value. Tried struct.with_fields but not able to access the value.
Can someone please help me on this?