Skip to content

Commit

Permalink
Add JSON access query support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Piro-Rael committed Oct 6, 2021
1 parent e807fed commit 353ae4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ def visit_external_stage(self, external_stage, **kw):
external_stage.path,
external_stage.file_format)

def visit_json_getitem_op_binary(self, binary, operator, **kw):
return '%s[%s]' % (
self.process(binary.left, **kw),
self.process(binary.right, **kw)
)

def delete_extra_from_clause(self, delete_stmt, from_table,
extra_froms, from_hints, **kw):
return "USING " + ', '.join(
Expand Down
15 changes: 12 additions & 3 deletions test/test_compiler.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sqlalchemy import Integer, String, and_, select
from sqlalchemy import Integer, JSON, String, and_, select
from sqlalchemy.sql import column, quoted_name, table
from sqlalchemy.testing import AssertsCompiledSQL

table1 = table(
'table1',
column('id', Integer),
column('name', String),
column('value', Integer)
column('value', Integer),
column('metadata', JSON)
)

table2 = table(
Expand All @@ -19,7 +20,6 @@
column('value', Integer)
)


class TestSnowflakeCompiler(AssertsCompiledSQL):
__dialect__ = "snowflake"

Expand Down Expand Up @@ -55,6 +55,15 @@ def test_multi_table_update(self):
)


def test_json_getitem(self):
statement = table1.select() \
.with_only_columns([table1.c.metadata['size'].label('size')])
self.assert_compile(
statement,
"SELECT data['size'] AS size FROM table1"
)


def test_quoted_name_label(engine_testaccount):
test_cases = [
# quote name
Expand Down

0 comments on commit 353ae4d

Please sign in to comment.