Skip to content

Commit

Permalink
fix 5372 add alias to json table function (#5375)
Browse files Browse the repository at this point in the history
* fix 5372 add alias

Add grammar for alias
Update mixin to use table alias if available
Add fixture test

* Update JsonTable.sq

Add use of alias for json function
  • Loading branch information
griffio committed Jul 26, 2024
1 parent 4325311 commit c4084ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
overrides ::= table_or_subquery

table_or_subquery ::= ( json_function_name LP <<expr '-1'>> ( COMMA <<expr '-1'>> ) * RP
table_or_subquery ::= ( json_function_name LP <<expr '-1'>> ( COMMA <<expr '-1'>> ) * RP [ [ AS ] {table_alias} ]
| [ {database_name} DOT ] {table_name} [ [ AS ] {table_alias} ] [ INDEXED BY {index_name} | NOT INDEXED ]
| LP ( {table_or_subquery} ( COMMA {table_or_subquery} ) * | {join_clause} ) RP
| LP {compound_select_stmt} RP [ [ AS ] {table_alias} ] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal abstract class TableOrSubqueryMixin(node: ASTNode?) :
if (jsonFunctionName != null) {
return@lazy listOf(
QueryResult(
table = jsonFunctionName!!,
table = tableAlias ?: jsonFunctionName!!,
columns = emptyList(),
synthesizedColumns = listOf(
SynthesizedColumn(jsonFunctionName!!, acceptableValues = listOf("key", "value", "type", "atom", "id", "parent", "fullkey", "path", "json", "root")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ SELECT DISTINCT json_extract(big.json,'$.id')
WHERE json_tree.value = 'uidle_since'
)
WHERE (uidle_since >= ? AND uidle_since <= ?)
AND is_deleted = 0;
AND is_deleted = 0;

SELECT json_extract(child.value, '$.d') FROM user, json_each(user.name, '$.a.b') AS parent, json_each(parent.value, '$.c') AS child;



Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ VALUES (?, ?);

byAreaCode:
SELECT DISTINCT user.name
FROM user, json_each(user.phone)
WHERE json_each.value LIKE :areaCode || '-%';
FROM user, json_each(user.phone) AS user_phone
WHERE user_phone.value LIKE :areaCode || '-%';

byAreaCode2:
SELECT name FROM user WHERE phone LIKE :areaCode || '-%'
UNION
SELECT user.name
FROM user, json_each(user.phone)
WHERE json_valid(user.phone)
AND json_each.value LIKE :areaCode || '-%';
AND json_each.value LIKE :areaCode || '-%';

0 comments on commit c4084ee

Please sign in to comment.