Skip to content

Commit

Permalink
Merge pull request #1394 from mabel-dev/#1393
Browse files Browse the repository at this point in the history
  • Loading branch information
joocer authored Jan 22, 2024
2 parents 3e06b5e + 839cfc6 commit 188096b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion opteryx/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__build__ = 224
__build__ = 226

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
10 changes: 7 additions & 3 deletions opteryx/operators/function_dataset_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

def _generate_series(**kwargs):
value_array = series.generate_series(*kwargs["args"])
return [{kwargs["columns"][0].schema_column.identity: value} for value in value_array]
column_name = kwargs["columns"][0].schema_column.identity
return pyarrow.Table.from_arrays([value_array], [column_name])


def _unnest(**kwargs):
Expand All @@ -41,7 +42,8 @@ def _unnest(**kwargs):
else:
list_items = kwargs["args"][0].value
column_name = kwargs["columns"][0].schema_column.identity
return [{column_name: row} for row in list_items]

return pyarrow.Table.from_arrays([list_items], [column_name])


def _values(**parameters):
Expand Down Expand Up @@ -108,8 +110,10 @@ def execute(self) -> Generator:

if isinstance(data, list):
table = pyarrow.Table.from_pylist(data)
if hasattr(data, "arrow"):
elif hasattr(data, "arrow"):
table = data.arrow()
else:
table = data

self.statistics.rows_read += table.num_rows
self.statistics.columns_read += len(table.column_names)
Expand Down
5 changes: 4 additions & 1 deletion opteryx/utils/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy
from orso.types import OrsoTypes

from opteryx.exceptions import InvalidFunctionParameterError
from opteryx.exceptions import SqlError
from opteryx.utils import dates

Expand All @@ -39,7 +40,9 @@ def generate_series(*args):
raise SqlError("generate_series for dates needs start, end, and interval parameters")
return dates.date_range(*arg_vals)

raise SqlError("Unsupported value for GENERATE_SERIES")
raise InvalidFunctionParameterError(
"Unsupported value for GENERATE_SERIES, must be date or numeric series."
)


def numeric_range(*args) -> numpy.ndarray:
Expand Down
7 changes: 3 additions & 4 deletions opteryx/virtual_datasets/no_table_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
def read(*args):
import pyarrow

# Create a PyArrow schema with one column called '$column' of integer type
_schema = pyarrow.schema([("$column", pyarrow.int64())])
# Create a PyArrow table with the given schema and one row
return pyarrow.Table.from_arrays([[None]], schema=_schema)
# Create a PyArrow table with one column and one row

return pyarrow.Table.from_arrays([[0]], ["$column"]) # schema=_schema)


def schema():
Expand Down
19 changes: 9 additions & 10 deletions opteryx/virtual_datasets/planet_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,20 @@ def read(end_date=None, *args):
full_set = pyarrow.Table.from_arrays(data, column_names)

if end_date is None:
end_date = datetime.datetime.utcnow()
return full_set

# Make the planet data act like it supports temporality
mask = [True, True, True, True, True, True, True, True, True]
if end_date < datetime.datetime(1930, 3, 13):
# March 13, 1930 - Pluto discovered by Clyde William Tombaugh
mask = [True, True, True, True, True, True, True, True, False]
if end_date < datetime.datetime(1846, 11, 13):
# November 13, 1846 - Neptune
mask = [True, True, True, True, True, True, True, False, False]
if end_date < datetime.datetime(1781, 4, 26):
# April 26, 1781 - Uranus discovered by Sir William Herschel
mask = [True, True, True, True, True, True, False, False, False]
return full_set.take([0, 1, 2, 3, 4, 5])
if end_date < datetime.datetime(1846, 11, 13):
# November 13, 1846 - Neptune
return full_set.take([0, 1, 2, 3, 4, 5, 7])
if end_date < datetime.datetime(1930, 3, 13):
# March 13, 1930 - Pluto discovered by Clyde William Tombaugh
return full_set.take([0, 1, 2, 3, 4, 5, 6, 7])

return full_set.filter(mask)
return full_set


def schema():
Expand Down

0 comments on commit 188096b

Please sign in to comment.