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

Table_scan column projection #578

Merged
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
5 changes: 4 additions & 1 deletion dask_sql/physical/rel/logical/table_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def convert(
# otherwise get all projected columns from the 'Projection' instance, which is contained
# in the 'RelDataType' instance, aka 'row_type'
if table_scan.containsProjections():
field_specifications = table_scan.getTableScanProjects()
field_specifications = (
table_scan.getTableScanProjects()
) # Assumes these are column projections only and field names match table column names
df = df[field_specifications]
else:
field_specifications = [str(f) for f in table.getRowType().getFieldNames()]

Expand Down
18 changes: 13 additions & 5 deletions tests/integration/test_select.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pandas as pd
import pytest
from dask.dataframe.optimize import optimize_dataframe_getitem
from dask.utils_test import hlg_layer

from dask_sql.utils import ParsingException
from tests.utils import assert_eq
Expand Down Expand Up @@ -226,7 +228,7 @@ def test_case_when_no_else(c):
assert_eq(actual_df, expected_df, check_dtype=False)


def test_singular_column_projection_simple(c):
ayushdg marked this conversation as resolved.
Show resolved Hide resolved
def test_singular_column_selection(c):
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
c.create_table("df", df)

Expand All @@ -246,10 +248,16 @@ def test_singular_column_projection_simple(c):
["a", "b", "d"],
],
)
def test_multiple_column_projection(c, input_cols):
def test_multiple_column_projection(c, parquet_ddf, input_cols):
ayushdg marked this conversation as resolved.
Show resolved Hide resolved
projection_list = ", ".join(input_cols)
result = c.sql(f"SELECT {projection_list} from parquet_ddf")
result_df = c.sql(f"SELECT {projection_list} from parquet_ddf")

# There are 5 columns in the table, ensure only specified ones are read
assert_eq(len(result.columns), len(input_cols))
assert all(x in input_cols for x in result.columns)
assert_eq(len(result_df.columns), len(input_cols))
assert_eq(parquet_ddf[input_cols], result_df)
assert sorted(
hlg_layer(
optimize_dataframe_getitem(result_df.dask, result_df.__dask_keys__()),
"read-parquet",
).columns
) == sorted(input_cols)