Skip to content
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
Binary file added dask_sql/.datacontainer.py.swp
Binary file not shown.
12 changes: 10 additions & 2 deletions dask_sql/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,16 @@ def _get_ral(self, sql):
# get the schema of what we currently have registered
schemas = self._prepare_schemas()

# Now create a relational algebra from that
generator_builder = RelationalAlgebraGeneratorBuilder(self.schema_name)
# True if the SQL query should be case sensitive and False otherwise
case_sensitive = (
self.schema[self.schema_name]
.config.get_config_by_prefix("dask.sql.identifier.case.sensitive")
.get("dask.sql.identifier.case.sensitive", True)
)

generator_builder = RelationalAlgebraGeneratorBuilder(
self.schema_name, case_sensitive
)
for schema in schemas:
generator_builder.addSchema(schema)
generator = generator_builder.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public class RelationalAlgebraGenerator {
final HepPlanner hepPlanner;

/// Create a new relational algebra generator from a schema
public RelationalAlgebraGenerator(final String rootSchemaName, final List<DaskSchema> schemas) throws ClassNotFoundException, SQLException {
public RelationalAlgebraGenerator(final String rootSchemaName, final List<DaskSchema> schemas, final boolean case_sensitive) throws ClassNotFoundException, SQLException {
// Taken from https://calcite.apache.org/docs/ and blazingSQL
final SchemaPlus rootSchema = createRootSchema(rootSchemaName, schemas);

final JavaTypeFactoryImpl typeFactory = createTypeFactory();
final CalciteCatalogReader calciteCatalogReader = createCatalogReader(rootSchemaName, rootSchema, typeFactory);
final SqlOperatorTable operatorTable = createOperatorTable(calciteCatalogReader);
final SqlParser.Config parserConfig = createParserConfig();
final SqlParser.Config parserConfig = createParserConfig(case_sensitive);
final SchemaPlus schemaPlus = rootSchema.getSubSchema(rootSchemaName);
final FrameworkConfig frameworkConfig = createFrameworkConfig(schemaPlus, operatorTable, parserConfig);

Expand Down Expand Up @@ -180,8 +180,9 @@ private SqlOperatorTable createOperatorTable(final CalciteCatalogReader calciteC
return operatorTable;
}

private Config createParserConfig() {
private Config createParserConfig(boolean case_sensitive) {
return getDialect().configureParser(SqlParser.Config.DEFAULT).withConformance(SqlConformanceEnum.DEFAULT)
.withCaseSensitive(case_sensitive)
.withParserFactory(new DaskSqlParserImplFactory());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
public class RelationalAlgebraGeneratorBuilder {
private final String rootSchemaName;
private final List<DaskSchema> schemas;
private final boolean case_sensitive; // True if case should be ignored when comparing SQLNode(s)

public RelationalAlgebraGeneratorBuilder(final String rootSchemaName) {
public RelationalAlgebraGeneratorBuilder(final String rootSchemaName, final boolean case_sensitive) {
this.rootSchemaName = rootSchemaName;
this.schemas = new ArrayList<>();
this.case_sensitive = case_sensitive;
}

public RelationalAlgebraGeneratorBuilder addSchema(final DaskSchema schema) {
Expand All @@ -21,6 +23,6 @@ public RelationalAlgebraGeneratorBuilder addSchema(final DaskSchema schema) {
}

public RelationalAlgebraGenerator build() throws ClassNotFoundException, SQLException {
return new RelationalAlgebraGenerator(rootSchemaName, schemas);
return new RelationalAlgebraGenerator(rootSchemaName, schemas, case_sensitive);
}
}
14 changes: 14 additions & 0 deletions tests/integration/test_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pandas.testing import assert_frame_equal

from dask_sql import Context
from dask_sql.utils import ParsingException


def cast_datetime_to_string(df):
Expand Down Expand Up @@ -934,3 +935,16 @@ def test_integration_1():
""",
a=a,
)


def test_query_case_sensitivity():
c = Context()
c.set_config(("dask.sql.identifier.case.sensitive", False))
df = pd.DataFrame({"id": [0, 1]})

c.create_table("test", df)

try:
c.sql("select ID from test")
except ParsingException as pe:
assert False, f"Queries should be case insensitve but raised exception {pe}"
1 change: 1 addition & 0 deletions tests/integration/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_select_of_select_with_casing(c, df):
expected_df = pd.DataFrame(
{"AAA": df["a"] + df["b"], "aaa": 2 * df["b"], "aAa": df["a"] - 1}
)

assert_frame_equal(result_df, expected_df)


Expand Down