Skip to content

Commit

Permalink
Allow pinot table aliases (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
abloom authored May 2, 2024
1 parent bfdd768 commit 5641180
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
7 changes: 2 additions & 5 deletions pinotdb/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def visit_select(self, select, **kwargs):
return super().visit_select(select, **kwargs)

def visit_column(self, column, result_map=None, **kwargs):
# Pinot does not support table aliases
if column.table is not None:
column.table.named_with_column = False
result_map = result_map or kwargs.pop("add_to_result_map", None)
# This is a hack to modify the original column, but how do I clone it ?
column.is_literal = True
Expand Down Expand Up @@ -61,7 +58,7 @@ def visit_REAL(self, type_, **kwargs):
return "DOUBLE"

def visit_NUMERIC(self, type_, **kwargs):
return "LONG"
return "NUMERIC"

visit_DECIMAL = visit_NUMERIC
visit_INTEGER = visit_NUMERIC
Expand All @@ -72,7 +69,7 @@ def visit_NUMERIC(self, type_, **kwargs):
visit_DATE = visit_NUMERIC

def visit_CHAR(self, type_, **kwargs):
return "STRING"
return "VARCHAR"

visit_NCHAR = visit_CHAR
visit_VARCHAR = visit_CHAR
Expand Down
28 changes: 14 additions & 14 deletions tests/unit/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def test_can_select_table_directly(self):

self.assertEqual(
str(compiler),
'SELECT some_column \nFROM some_table',
'SELECT some_table.some_column \nFROM some_table',
)


Expand All @@ -357,44 +357,44 @@ def test_compiles_real(self):
self.assertEqual(self.compiler.visit_REAL(None), 'DOUBLE')

def test_compiles_numeric(self):
self.assertEqual(self.compiler.visit_NUMERIC(None), 'LONG')
self.assertEqual(self.compiler.visit_NUMERIC(None), 'NUMERIC')

def test_compiles_decimal(self):
self.assertEqual(self.compiler.visit_DECIMAL(None), 'LONG')
self.assertEqual(self.compiler.visit_DECIMAL(None), 'NUMERIC')

def test_compiles_integer(self):
self.assertEqual(self.compiler.visit_INTEGER(None), 'LONG')
self.assertEqual(self.compiler.visit_INTEGER(None), 'NUMERIC')

def test_compiles_smallint(self):
self.assertEqual(self.compiler.visit_SMALLINT(None), 'LONG')
self.assertEqual(self.compiler.visit_SMALLINT(None), 'NUMERIC')

def test_compiles_bigint(self):
self.assertEqual(self.compiler.visit_BIGINT(None), 'LONG')
self.assertEqual(self.compiler.visit_BIGINT(None), 'NUMERIC')

# TODO: Check if this is correct (seems strange to have boolean as long).
def test_compiles_boolean(self):
self.assertEqual(self.compiler.visit_BOOLEAN(None), 'LONG')
self.assertEqual(self.compiler.visit_BOOLEAN(None), 'NUMERIC')

def test_compiles_timestamp(self):
self.assertEqual(self.compiler.visit_TIMESTAMP(None), 'LONG')
self.assertEqual(self.compiler.visit_TIMESTAMP(None), 'NUMERIC')

def test_compiles_date(self):
self.assertEqual(self.compiler.visit_DATE(None), 'LONG')
self.assertEqual(self.compiler.visit_DATE(None), 'NUMERIC')

def test_compiles_char(self):
self.assertEqual(self.compiler.visit_CHAR(None), 'STRING')
self.assertEqual(self.compiler.visit_CHAR(None), 'VARCHAR')

def test_compiles_nchar(self):
self.assertEqual(self.compiler.visit_NCHAR(None), 'STRING')
self.assertEqual(self.compiler.visit_NCHAR(None), 'VARCHAR')

def test_compiles_varchar(self):
self.assertEqual(self.compiler.visit_VARCHAR(None), 'STRING')
self.assertEqual(self.compiler.visit_VARCHAR(None), 'VARCHAR')

def test_compiles_nvarchar(self):
self.assertEqual(self.compiler.visit_NVARCHAR(None), 'STRING')
self.assertEqual(self.compiler.visit_NVARCHAR(None), 'VARCHAR')

def test_compiles_text(self):
self.assertEqual(self.compiler.visit_TEXT(None), 'STRING')
self.assertEqual(self.compiler.visit_TEXT(None), 'VARCHAR')

def test_compiles_binary(self):
self.assertEqual(self.compiler.visit_BINARY(None), 'BYTES')
Expand Down

0 comments on commit 5641180

Please sign in to comment.