timestampdiff support
See original GitHub issuethe timestampdiff
operation currently fails to do missing reinterpret
implementation error.
Here’s a reproducer:
from dask_sql import Context
from dask import dataframe as dd
import pandas as pd
c = Context()
df = pd.DataFrame({"dt":["2002-06-05 00:00:00", "2005-09-01 00:00:00", "2003-12-03 00:00:00"]})
df2 = pd.DataFrame({"dt2":["2002-06-07 00:00:00", "2002-06-05 00:00:00", "2002-06-05 00:00:00"]})
c.create_table("df", df)
c.create_table("df2", df2)
query = "SELECT timestampdiff(DAY, CAST(dt AS TIMESTAMP), CAST(dt2 AS TIMESTAMP)) FROM df, df2"
c.sql(query)
Error with:
NotImplementedError Traceback (most recent call last)
/tmp/ipykernel_64215/3992071282.py in <module>
10
11 query = "SELECT timestampdiff(DAY, CAST(dt AS TIMESTAMP), CAST(dt2 AS TIMESTAMP)) FROM df, df2"
---> 12 c.sql(query)
lib/python3.8/site-packages/dask_sql/context.py in sql(self, sql, return_futures, dataframes)
421 rel, select_names, _ = self._get_ral(sql)
422
--> 423 dc = RelConverter.convert(rel, context=self)
424
425 if dc is None:
lib/python3.8/site-packages/dask_sql/physical/rel/convert.py in convert(cls, rel, context)
54 f"Processing REL {rel} using {plugin_instance.__class__.__name__}..."
55 )
---> 56 df = plugin_instance.convert(rel, context=context)
57 logger.debug(f"Processed REL {rel} into {LoggableDataFrame(df)}")
58 return df
lib/python3.8/site-packages/dask_sql/physical/rel/logical/project.py in convert(self, rel, context)
51 else:
52 random_name = new_temporary_column(df)
---> 53 new_columns[random_name] = RexConverter.convert(
54 expr, dc, context=context
55 )
lib/python3.8/site-packages/dask_sql/physical/rex/convert.py in convert(cls, rex, dc, context)
60 )
61
---> 62 df = plugin_instance.convert(rex, dc, context=context)
63 logger.debug(f"Processed REX {rex} into {LoggableDataFrame(df)}")
64 return df
lib/python3.8/site-packages/dask_sql/physical/rex/core/call.py in convert(self, rex, dc, context)
769 ) -> SeriesOrScalar:
770 # Prepare the operands by turning the RexNodes into python expressions
--> 771 operands = [
772 RexConverter.convert(o, dc, context=context) for o in rex.getOperands()
773 ]
lib/python3.8/site-packages/dask_sql/physical/rex/core/call.py in <listcomp>(.0)
770 # Prepare the operands by turning the RexNodes into python expressions
771 operands = [
--> 772 RexConverter.convert(o, dc, context=context) for o in rex.getOperands()
773 ]
774
lib/python3.8/site-packages/dask_sql/physical/rex/convert.py in convert(cls, rex, dc, context)
60 )
61
---> 62 df = plugin_instance.convert(rex, dc, context=context)
63 logger.debug(f"Processed REX {rex} into {LoggableDataFrame(df)}")
64 return df
lib/python3.8/site-packages/dask_sql/physical/rex/core/call.py in convert(self, rex, dc, context)
769 ) -> SeriesOrScalar:
770 # Prepare the operands by turning the RexNodes into python expressions
--> 771 operands = [
772 RexConverter.convert(o, dc, context=context) for o in rex.getOperands()
773 ]
lib/python3.8/site-packages/dask_sql/physical/rex/core/call.py in <listcomp>(.0)
770 # Prepare the operands by turning the RexNodes into python expressions
771 operands = [
--> 772 RexConverter.convert(o, dc, context=context) for o in rex.getOperands()
773 ]
774
lib/python3.8/site-packages/dask_sql/physical/rex/convert.py in convert(cls, rex, dc, context)
60 )
61
---> 62 df = plugin_instance.convert(rex, dc, context=context)
63 logger.debug(f"Processed REX {rex} into {LoggableDataFrame(df)}")
64 return df
lib/python3.8/site-packages/dask_sql/physical/rex/core/call.py in convert(self, rex, dc, context)
783 operation = context.schema[schema_name].functions[operator_name]
784 except KeyError: # pragma: no cover
--> 785 raise NotImplementedError(f"{operator_name} not (yet) implemented")
786
787 logger.debug(
NotImplementedError: reinterpret not (yet) implemented
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
MySQL TIMESTAMPDIFF() function - w3resource
MySQL the TIMESTAMPDIFF() returns a value after subtracting a datetime expression from another.
Read more >TIMESTAMPDIFF - IBM
The TIMESTAMPDIFF function returns an estimated number of intervals of the type defined by the first argument, based on the difference between two...
Read more >TIMESTAMPDIFF - MariaDB Knowledge Base
... the TIMESTAMPADD() function, i.e MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR. TIMESTAMPDIFF can also be used to calculate age....
Read more >MySQL TIMESTAMPDIFF Function - Tutorial Gateway
MySQL TIMESTAMPDIFF function is one of the Date methods, which is useful to find the interval difference between two dates or DateTime expressions....
Read more >MySQL 8.0 Reference Manual :: 12.7 Date and Time Functions
TIMESTAMPDIFF (), Subtract an interval from a datetime expression ... See Section 5.1.15, “MySQL Server Time Zone Support”. Some date functions can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rajagurunath I think it would be good if you could open a WIP PR. That would allow us to discuss a little more and also take advantage of CI for testing theories and changes.
I have been looking into this a bit more and updating #293 locally to work with the latest branch. On further inspection it looks like the main issue with
month
andyear
comes from calcite assuming a differenttime_interval
for the date subtraction vs the other time units. Currently we handle theSqlDatetimeSubtractionOperator
the same as any regular subtraction operation but I think we might need a way to extract the time units for this operation as well from calcite based on the docs here.I’ll look into this further to see how to get that from calcite.