Skip to content
Closed
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
75 changes: 73 additions & 2 deletions sql-jdbc/src/TableauConnector/opensearch_sql_jdbc/dialect.tdd
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,87 @@
<argument type='datetime' />
<argument type='datetime' />
</function>

<function group='operator' name='==' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) AS TIMESTAMP)) = CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='date' />
<argument type='datetime' />
</function>
<function group='operator' name='==' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) AS TIMESTAMP)) = CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='datetime' />
Copy link

Choose a reason for hiding this comment

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

I think just calling TIMESTAMP would cause an issue where the time would not be 00:00:00 as expected. We have to do something like SUBDATE(TIMESTAMP(DATE(%2)), INTERVAL HOUR(TIMESTAMP(DATE(%2))) HOUR). This will likely result in a an error logged in this issue.

Copy link
Author

Choose a reason for hiding this comment

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

It works fine, see the test on the pic:
image

<argument type='date' />
</function>
<function group='operator' name='!=' return-type='bool'>
<formula>(CAST(DATE_FORMAT(DATE(%1), '%Y-%m-%d 00:00:00') AS TIMESTAMP) &lt;&gt; %2)</formula>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) AS TIMESTAMP)) &lt;&gt; CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='date' />
<argument type='datetime' />
</function>
<function group='operator' name='!=' return-type='bool'>
<formula>(%1 &lt;&gt; CAST(DATE_FORMAT(DATE(%2), '%Y-%m-%d 00:00:00') AS TIMESTAMP))</formula>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) AS TIMESTAMP)) &lt;&gt; CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='datetime' />
<argument type='date' />
</function>
<function group='operator' name='&gt;=' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) AS TIMESTAMP)) &gt;= CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='date' />
<argument type='datetime' />
</function>
<function group='operator' name='&gt;=' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) AS TIMESTAMP)) &gt;= CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='datetime' />
<argument type='date' />
</function>
<function group='operator' name='&lt;=' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP)) &lt;= CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='date' />
<argument type='datetime' />
</function>
<function group='operator' name='&lt;=' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP)) &lt;= CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='datetime' />
<argument type='date' />
</function>
<function group='operator' name='&gt;' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP)) &gt; CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='date' />
<argument type='datetime' />
</function>
<function group='operator' name='&gt;' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP)) &gt; CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='datetime' />
<argument type='date' />
</function>
<function group='operator' name='&lt;' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP)) &lt; CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='date' />
<argument type='datetime' />
</function>
<function group='operator' name='&lt;' return-type='bool'>
<formula>(CAST(DATE_FORMAT(%1, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP)) &lt; CAST(DATE_FORMAT(%2, &apos;%Y-%m-%d %H:%i:%s&apos;) as TIMESTAMP))</formula>
<argument type='datetime' />
<argument type='date' />
</function>

<function group='operator' name='-' return-type='real'>
<!-- 86400 as it represents seconds in a day -->
<formula>((TO_DAYS(CAST(%1 as TIMESTAMP)) - TO_DAYS(CAST(%2 as TIMESTAMP))) + ((TIME_TO_SEC(CAST(%1 as TIMESTAMP)) - TIME_TO_SEC(CAST(%2 as TIMESTAMP))) / 86400.0))</formula>
Copy link

@ghost ghost Nov 23, 2021

Choose a reason for hiding this comment

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

Casting DATE to TIMESTAMP doesn't work. We have to use TIMESTAMP() or DATE_FORMAT. Ideally we should use SUBDATE(TIMESTAMP(%2), INTERVAL HOUR(TIMESTAMP(%2)) HOUR).

<argument type='date' />
<argument type='datetime' />
</function>
<function group='operator' name='-' return-type='real'>
<!-- 86400 as it represents seconds in a day -->
<formula>((TO_DAYS(CAST(%1 as TIMESTAMP)) - TO_DAYS(CAST(%2 as TIMESTAMP))) + ((TIME_TO_SEC(CAST(%1 as TIMESTAMP)) - TIME_TO_SEC(CAST(%2 as TIMESTAMP))) / 86400.0))</formula>
<argument type='datetime' />
<argument type='date' />
</function>
<function group='operator' name='-' return-type='real'>
<!-- 86400 as it represents seconds in a day -->
<formula>((TO_DAYS(CAST(%1 as TIMESTAMP)) - TO_DAYS(CAST(%2 as TIMESTAMP))) + ((TIME_TO_SEC(CAST(%1 as TIMESTAMP)) - TIME_TO_SEC(CAST(%2 as TIMESTAMP))) / 86400.0))</formula>
<argument type='datetime' />
<argument type='datetime' />
</function>

<function group='operator' name='+' return-type='datetime'>
<!-- 86400 as it represents seconds in a day -->
<formula>DATE_ADD(DATE_ADD(%1, INTERVAL FLOOR(%2) DAY), INTERVAL CAST(86400 * (%2 - FLOOR(%2)) AS INT) SECOND)</formula>
Expand Down