Skip to content

Commit

Permalink
fix: evadb is now consistent with lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav274 committed Sep 11, 2023
1 parent 5a3efce commit 8773302
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions evadb/binder/binder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def create_table_catalog_entry_for_data_source(
]
column_list = []
for name, dtype in zip(column_name_list, column_type_list):
column_list.append(ColumnCatalogEntry(name, dtype))
column_list.append(ColumnCatalogEntry(name.lower(), dtype))

# Assemble table.
table_catalog_entry = TableCatalogEntry(
Expand Down Expand Up @@ -339,7 +339,7 @@ def get_column_definition_from_select_target_list(
for col_name, output_obj in output_objs:
binded_col_list.append(
ColumnDefinition(
col_name,
col_name.lower(),
output_obj.type,
output_obj.array_type,
output_obj.array_dimensions,
Expand Down
3 changes: 3 additions & 0 deletions evadb/binder/statement_binder_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def get_binded_column(
A tuple of alias and column object
"""

# binder is case insensitive
col_name = col_name.lower()

def raise_error():
err_msg = f"Found invalid column {col_name}"
logger.error(err_msg)
Expand Down
7 changes: 7 additions & 0 deletions evadb/storage/native_storage_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def read(self, database_name: str, table: TableCatalogEntry) -> Iterator[Batch]:
handler.connect()

data_df = handler.execute_native_query(f"SELECT * FROM {table.name}").data

# Handling case-sensitive databases like SQLite can be tricky. Currently,
# EvaDB converts all columns to lowercase, which may result in issues with
# these databases. As we move forward, we are actively working on improving
# this aspect within Binder.
# For more information, please refer to https://github.com/georgia-tech-db/evadb/issues/1079.
data_df.columns = data_df.columns.str.lower()
yield Batch(pd.DataFrame(data_df))

except Exception as e:
Expand Down
8 changes: 7 additions & 1 deletion evadb/third_party/databases/sqlite/sqlite_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ def get_columns(self, table_name: str) -> DBHandlerResponse:

def _fetch_results_as_df(self, cursor):
try:
# Handling case-sensitive databases like SQLite can be tricky. Currently,
# EvaDB converts all columns to lowercase, which may result in issues with
# these databases. As we move forward, we are actively working on improving
# this aspect within Binder.
# For more information, please refer to https://github.com/georgia-tech-db/evadb/issues/1079.

res = cursor.fetchall()
res_df = pd.DataFrame(
res,
columns=[desc[0] for desc in cursor.description]
columns=[desc[0].lower() for desc in cursor.description]
if cursor.description
else [],
)
Expand Down
10 changes: 5 additions & 5 deletions test/third_party_tests/test_native_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _create_table_in_native_database(self):
"""USE test_data_source {
CREATE TABLE test_table (
name VARCHAR(10),
age INT,
Age INT,
comment VARCHAR (100)
)
}""",
Expand All @@ -49,7 +49,7 @@ def _insert_value_into_native_database(self, col1, col2, col3):
self.evadb,
f"""USE test_data_source {{
INSERT INTO test_table (
name, age, comment
name, Age, comment
) VALUES (
'{col1}', {col2}, '{col3}'
)
Expand All @@ -67,7 +67,7 @@ def _drop_table_in_native_database(self):
def _create_evadb_table_using_select_query(self):
execute_query_fetch_all(
self.evadb,
"""CREATE TABLE eva_table AS SELECT name, age FROM test_data_source.test_table;""",
"""CREATE TABLE eva_table AS SELECT name, Age FROM test_data_source.test_table;""",
)

# check if the create table is successful
Expand Down Expand Up @@ -150,7 +150,7 @@ def _raise_error_on_invalid_connection(self):
def test_should_run_query_in_postgres(self):
# Create database.
params = {
"user": "eva",
"user": "gkakkar7",
"password": "password",
"host": "localhost",
"port": "5432",
Expand All @@ -169,7 +169,7 @@ def test_should_run_query_in_postgres(self):
self._raise_error_on_multiple_creation()
self._raise_error_on_invalid_connection()

def test_should_run_query_in_sqlite(self):
def test_aaashould_run_query_in_sqlite(self):
# Create database.
params = {
"database": "evadb.db",
Expand Down

0 comments on commit 8773302

Please sign in to comment.