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

Drill incorrectly translates date/time function when using RDBMS plug-in with underlying MSSQL datasource. #2846

Open
brainpow3r opened this issue Nov 8, 2023 · 0 comments
Labels

Comments

@brainpow3r
Copy link

brainpow3r commented Nov 8, 2023

Describe the bug
We have an Apache Drill instance set up and running in embedded mode. RDBMS plug-in is used to connect existing MSSQL database to Drill. Plug-in configuration looks like this

{ "type": "jdbc", "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver", "url": "jdbc:sqlserver://*********;databaseName=*******", "username": "MyUserName", "password": "MyPassword", "sourceParameters": { "keepaliveTime": 0, "minimumIdle": 0, "idleTimeout": 3600000, "maximumPoolSize": 10, "maxLifetime": 21600000 }, "authMode": "SHARED_USER", "writerBatchSize": 10000, "enabled": true }

Most of the statements we tried running through Drill works fine. But recently we wrote a couple of queries where we need to extract month from a date field and we encountered some errors. More precisely:

When executing following SQL statement
select YEAR(DateColumn) from rdbms_schema.MyTable

We receive such error response from Apache Drill

org.apache.drill.common.exceptions.UserRemoteException: DATA_READ ERROR: The JDBC storage plugin failed while trying setup the SQL query. Sql: SELECT EXTRACT(YEAR FROM "DateColumn") FROM "rdbms_schema"."MyTable" Fragment: 0:0

From which we can see that Drill actually translates our query before passing to MSSQL server to use EXTRACT(...), but the problem is that EXTRACT keyword is not supported in MSSQL server.

To Reproduce
Steps to reproduce the behavior:

  1. Set up Apache Drill instance in embedded mode and an MSSQL Server instance.
  2. Create a database and a table inside it with date/datetime/datetime2 column.
  3. Add RDBMS plug-in to your Apache Drill instance and configure it to connect to your MSSQL Server instance.
  4. Try executing a query which extracts year/month/day from date/datetime/datetime2 column. Something along the lines of SELECT MONTH([DateColumn]) FROM rdbms_schema.MyTable
  5. See error.

Expected behavior
Query should be translated to support underlying RDBMS datasource keywords and functions.

Drill version
1.21.1

Additional context
As a workaround we tried getting the month field by using FORMAT like this (equivalent works in MSSQL server):
select FORMAT(DateColumn, 'MM') from rdbms_schema.MyTable

But we received the following error:
org.apache.drill.common.exceptions.UserRemoteException: VALIDATION ERROR: From line 1, column 8 to line 1, column 27: No match found for function signature FORMAT(<DATE>, <CHARACTER>)

EDIT: Formatting

@brainpow3r brainpow3r added the bug label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant