Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON access query support #245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 table1.metadata['size'] AS size FROM table1"
)


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