Skip to content

Commit

Permalink
Keep casing also with unquoted identifiers. Fixes #84.
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-braun committed Nov 28, 2020
1 parent ad53a36 commit ce59baf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/pages/sql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ General
-------

Identifiers can be specified with double quotes or without quotes (if there is no ambiguity with SQL keywords).
Casing with be kept (with or without quotes).

.. code-block:: sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.dask.sql.schema.DaskSchema;
import org.apache.calcite.sql.SqlDialect;
import org.apache.calcite.sql.dialect.PostgresqlSqlDialect;

import org.apache.calcite.avatica.util.Casing;
import org.apache.calcite.config.CalciteConnectionConfigImpl;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.jdbc.CalciteSchema;
Expand Down Expand Up @@ -108,7 +108,11 @@ private FrameworkConfig getConfig(final SchemaPlus rootSchema, final String sche

/// Return the default dialect used
public SqlDialect getDialect() {
return PostgresqlSqlDialect.DEFAULT;
// This is basically PostgreSQL, but we would like to keep the casing
// of unquoted table identifiers, as this is what pandas/dask
// would also do.
// See https://github.com/nils-braun/dask-sql/issues/84
return new PostgresqlSqlDialect(PostgresqlSqlDialect.DEFAULT_CONTEXT.withUnquotedCasing(Casing.UNCHANGED));
}

/// Get a connection to "connect" to the database.
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ def test_select_of_select(c, df):
assert_frame_equal(result_df, expected_df)


def test_select_of_select_with_casing(c, df):
result_df = c.sql(
"""
SELECT AAA, aaa, aAa
FROM
(
SELECT a - 1 AS aAa, 2*b AS aaa, a + b AS AAA
FROM df
) AS "inner"
"""
)
result_df = result_df.compute()

expected_df = pd.DataFrame(
{"AAA": df["a"] + df["b"], "aaa": 2 * df["b"], "aAa": df["a"] - 1}
)
assert_frame_equal(result_df, expected_df)


def test_wrong_input(c):
with pytest.raises(ParsingException):
c.sql("""SELECT x FROM df""")
Expand Down

0 comments on commit ce59baf

Please sign in to comment.