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

Fixed issue #291 and updated the dialect for Tableau Connector #296

Merged
merged 25 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
040552f
Added Tableau Connector to OpenSearch SQL
Nov 17, 2021
c8ddfb9
Merge pull request #1 from Bit-Quill/migrate-jdbc-tableau-connector
Nov 18, 2021
952ff01
Added CEILING and FLOOR functions
Nov 18, 2021
dd357bc
Merge pull request #2 from Bit-Quill/dialect-ceilfloor-AOS220
Nov 18, 2021
580e1af
Added IFNULL function
Nov 18, 2021
a4d2c0c
Added Kyle's fix for ADDDATE and SUBDATE with resulting 00:00:00 bein…
Nov 18, 2021
10aba05
Added MIN and MAX for two string arguments
Nov 18, 2021
5a90ca7
Merge pull request #3 from Bit-Quill/timestamp-issue
Nov 18, 2021
fa32866
Fixed return type for MID function redefenitions, part of AOS-202
Yury-Fridlyand Nov 19, 2021
b852f9d
Added CAST functions to convert to int or string as part of AOS-202
Yury-Fridlyand Nov 19, 2021
65437b2
Added HEXBINX and HEXBINY functions from the templace without any mod…
Yury-Fridlyand Nov 20, 2021
2e50a43
Fixed cast to use the OSSQL type
Yury-Fridlyand Nov 20, 2021
177d132
Added parenthesis to avoid opensearch-project/sql/issues/293
Yury-Fridlyand Nov 20, 2021
2355abf
Merge pull request #6 from Bit-Quill/dialect-strings-AOS-202-CAST
Yury-Fridlyand Nov 20, 2021
0df001a
Pulled from main from OpenSearch
Nov 22, 2021
8596513
Merge branch 'main' of github.com:Bit-Quill/opensearch-project-sql in…
Nov 22, 2021
f212e35
Modified Timestamp conversion formula
Nov 22, 2021
2df3f26
Merge pull request #8 from Bit-Quill/dialect-expr-logical-AOS205
Nov 23, 2021
7aaf59d
Merge pull request #5 from Bit-Quill/dialect-fix-MID-return-type-AOS-202
Yury-Fridlyand Nov 23, 2021
8d8fa1a
Merge pull request #7 from Bit-Quill/dialect-math.hexbin-AOS-195
Yury-Fridlyand Nov 23, 2021
385a41b
Added comment to TimestampType
Nov 23, 2021
26dbb7e
Updated Company Name accroding to the customer's request
Yury-Fridlyand Nov 23, 2021
3a5271e
Merge pull request #9 from Bit-Quill/update-vendor-AOS-231
Yury-Fridlyand Nov 24, 2021
4c63b64
Updated Vendor Name as well
Yury-Fridlyand Nov 24, 2021
edd2159
Merge pull request #10 from Bit-Quill/update-vendor-AOS-231-part-2
Yury-Fridlyand Nov 25, 2021
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
94 changes: 71 additions & 23 deletions sql-jdbc/src/TableauConnector/opensearch_sql_jdbc/dialect.tdd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@
<formula>TO_DAYS(%1) - 693961.0</formula>
<argument type='datetime' />
</function>
<function group='cast' name='STR' return-type='str'>
<formula>CAST(%1 as string)</formula>
<argument type='real' />
</function>
<function group='cast' name='STR' return-type='str'>
<formula>CAST(%1 as string)</formula>
<argument type='int' />
</function>
<function group='cast' name='STR' return-type='str'>
<formula>CAST(%1 as string)</formula>
<argument type='date' />
</function>
<function group='cast' name='STR' return-type='str'>
<formula>CAST(%1 as string)</formula>
<argument type='bool' />
</function>
<function group='cast' name='INT' return-type='int'>
<formula>CAST(%1 as int)</formula>
<argument type='real' />
</function>
<function group='cast' name='INT' return-type='int'>
<formula>CAST(%1 as int)</formula>
<argument type='bool' />
</function>

<function group='logical' name='IFNULL' return-type='datetime'>
<formula>CASE WHEN ISNULL(%1) THEN SUBDATE(TIMESTAMP(%2), INTERVAL HOUR(TIMESTAMP(%2)) HOUR) ELSE %1 END</formula>
<argument type='datetime' />
<argument type='date' />
</function>

<function group='operator' name='!=' return-type='bool'>
<formula>(%1 AND NOT %2 OR NOT %1 AND %2)</formula>
Expand Down Expand Up @@ -150,6 +180,14 @@
<argument type='datetime' />
<argument type='datetime' />
</function>
<function group='numeric' name='MAX' return-type='str'>
<formula>CASE WHEN ISNULL(%1) THEN NULL
WHEN ISNULL(%2) THEN NULL
WHEN %1 &gt; %2 THEN %1
ELSE %2 END</formula>
<argument type='str' />
<argument type='str' />
</function>
<function group='numeric' name='MIN' return-type='int'>
<formula>CASE WHEN ISNULL(%1) THEN NULL
WHEN ISNULL(%2) THEN NULL
Expand All @@ -174,7 +212,33 @@
<argument type='datetime' />
<argument type='datetime' />
</function>

<function group='numeric' name='MIN' return-type='str'>
<formula>CASE WHEN ISNULL(%1) THEN NULL
WHEN ISNULL(%2) THEN NULL
WHEN %1 &lt; %2 THEN %1
ELSE %2 END</formula>
<argument type='str' />
<argument type='str' />
</function>
<function group='numeric' name='CEILING' return-type='int'>
<formula>CEIL(%1)</formula>
<argument type='real' />
</function>
<function group='numeric' name='FLOOR' return-type='int'>
<formula>FLOOR(%1)</formula>
<argument type='real' />
</function>
<function group='numeric' name='HEXBINX' return-type='real'>
<formula>(((CASE WHEN (ABS((%2) - (CAST( ( (%2) / SQRT(3.0) ) AS INT ) * SQRT(3.0)))) + (SQRT(3.0) * ((ABS((%1) - (CAST( ( (%1) / 3.0 ) AS INT ) * 3.0))) - 1.0)) &gt; 0.0 THEN 1.5 ELSE 0.0 END) - (CASE WHEN ((%1) - (CAST( ( (%1) / 3.0 ) AS INT ) * 3.0) &lt; 0.0) AND ((CASE WHEN (ABS((%2) - (CAST( ( (%2) / SQRT(3.0) ) AS INT ) * SQRT(3.0)))) + (SQRT(3.0) * ((ABS((%1) - (CAST( ( (%1) / 3.0 ) AS INT ) * 3.0))) - 1.0)) &gt; 0.0 THEN 1.5 ELSE 0.0 END) &gt; 0.0) THEN 3.0 ELSE 0.0 END)) + (CAST( ( (%1) / 3.0 ) AS INT ) * 3.0))</formula>
<argument type='real' />
<argument type='real' />
</function>
<function group='numeric' name='HEXBINY' return-type='real'>
<formula>ROUND( (((CASE WHEN (ABS((%2) - (ROUND( ( (%2) / SQRT(3.0) ), 0 ) * SQRT(3.0)))) + (SQRT(3.0) * ((ABS((%1) - (ROUND( ( (%1) / 3.0 ), 0 ) * 3.0))) - 1.0)) &gt; 0.0 THEN SQRT(3.0) / 2.0 ELSE 0.0 END) - (CASE WHEN ((%2) - (ROUND( ( (%2) / SQRT(3.0) ), 0 ) * SQRT(3.0)) &lt; 0.0) AND ((CASE WHEN (ABS((%2) - (ROUND( ( (%2) / SQRT(3.0) ), 0 ) * SQRT(3.0)))) + (SQRT(3.0) * ((ABS((%1) - (ROUND( ( (%1) / 3.0 ), 0 ) * 3.0))) - 1.0)) &gt; 0.0 THEN SQRT(3.0) / 2.0 ELSE 0.0 END) &gt; 0.0) THEN SQRT(3.0) ELSE 0.0 END)) + (ROUND( ( (%2) / SQRT(3.0) ), 0 ) * SQRT(3.0))), 3)</formula>
<argument type='real' />
<argument type='real' />
</function>

<function group='date' name='DAYOFYEAR' return-type='int'>
<formula>DAY_OF_YEAR(%1)</formula>
<argument type='date' />
Expand All @@ -188,35 +252,35 @@
<argument type='date' />
</function>

<function group='string' name='MID' return-type='int'>
<function group='string' name='MID' return-type='str'>
<formula>SUBSTR(%1,%2)</formula>
<argument type='str' />
<argument type='int' />
</function>
<function group='string' name='MID' return-type='int'>
<function group='string' name='MID' return-type='str'>
<formula>SUBSTR(%1,CAST(%2 as int))</formula>
<argument type='str' />
<argument type='real' />
</function>
<function group='string' name='MID' return-type='int'>
<function group='string' name='MID' return-type='str'>
<formula>SUBSTR(%1,%2,%3)</formula>
<argument type='str' />
<argument type='int' />
<argument type='int' />
</function>
<function group='string' name='MID' return-type='int'>
<function group='string' name='MID' return-type='str'>
<formula>SUBSTR(%1,CAST(%2 as int),%3)</formula>
<argument type='str' />
<argument type='real' />
<argument type='int' />
</function>
<function group='string' name='MID' return-type='int'>
<function group='string' name='MID' return-type='str'>
<formula>SUBSTR(%1,%2,CAST(%3 as int))</formula>
<argument type='str' />
<argument type='int' />
<argument type='real' />
</function>
<function group='string' name='MID' return-type='int'>
<function group='string' name='MID' return-type='str'>
<formula>SUBSTR(%1,CAST(%2 as int),CAST(%3 as int))</formula>
<argument type='str' />
<argument type='real' />
Expand Down Expand Up @@ -326,24 +390,8 @@
<argument type='datetime' />
</remove-function>

<remove-function name='MAX'>
<argument type='str' />
</remove-function>
<remove-function name='MAX'>
<argument type='str' />
<argument type='str' />
</remove-function>

<remove-function name='SPACE'>
<argument type='int' />
</remove-function>

<remove-function name='MIN'>
<argument type='str' />
</remove-function>
<remove-function name='MIN'>
<argument type='str' />
<argument type='str' />
</remove-function>
</function-map>
</dialect>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Map;
Expand Down Expand Up @@ -78,13 +79,17 @@ else if (value.charAt(23) == '+' || value.charAt(23) == '-') {
}
}

if (calendar == null) {
return Timestamp.valueOf(value);
final Timestamp ts;
if (value.length() < 11) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question why 11 here? is it to check if value is in yyyy-MM-dd format?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I can add a comment to clarify this.

ts = Timestamp.valueOf(LocalDate.parse(value).atStartOfDay());
} else {
Timestamp ts = Timestamp.valueOf(value);
return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar);
ts = Timestamp.valueOf(value);
}

if (calendar == null) {
return ts;
}
return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar);
} catch (IllegalArgumentException iae) {
throw stringConversionException(value, iae);
}
Expand Down