Skip to content

Commit

Permalink
Merge pull request #2142 from mabel-dev/dependabot/cargo/sqlparser-0.…
Browse files Browse the repository at this point in the history
…53.0

Update sqlparser requirement from 0.52.0 to 0.53.0
  • Loading branch information
joocer authored Dec 29, 2024
2 parents 7d93b0c + e2544ce commit 570f50c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ version = "0.23"
features = ["extension-module"]

[dependencies.sqlparser]
version = "0.52.0"
version = "0.53.0"
features = ["serde", "visitor"]
2 changes: 1 addition & 1 deletion opteryx/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__build__ = 926
__build__ = 928

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
18 changes: 14 additions & 4 deletions opteryx/functions/number_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ def ceiling(values, scales=None) -> List:
scale = scales[0]
if scale == 0:
return numpy.ceil(values)
scale = 10**scale
return numpy.ceil(values * scale) / scale

if scale > 0:
scale_factor = 10**scale
return numpy.ceil(values * scale_factor) / scale_factor
else:
scale_factor = 10 ** (-scale)
return numpy.ceil(values / scale_factor) * scale_factor


def floor(values, scales=None) -> List:
Expand All @@ -104,5 +109,10 @@ def floor(values, scales=None) -> List:
scale = scales[0]
if scale == 0:
return numpy.floor(values)
scale = 10**scale
return numpy.floor(values * scale) / scale

if scale > 0:
scale_factor = 10**scale
return numpy.floor(values * scale_factor) / scale_factor
else:
scale_factor = 10 ** (-scale)
return numpy.floor(values / scale_factor) * scale_factor
5 changes: 5 additions & 0 deletions opteryx/planner/ast_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ def temporal_range_binder(ast, filters):
ast["table_name"][0]["start_date"] = temporal_range[1]
ast["table_name"][0]["end_date"] = temporal_range[2]
return ast
if "parent_name" in ast:
temporal_range = filters.pop(0)
ast["parent_name"][0]["start_date"] = temporal_range[1]
ast["parent_name"][0]["end_date"] = temporal_range[2]
return ast
if "ShowCreate" in ast and filters:
temporal_range = filters.pop(0)
ast["ShowCreate"]["start_date"] = temporal_range[1]
Expand Down
11 changes: 7 additions & 4 deletions opteryx/planner/logical_planner/logical_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,9 @@ def create_node_relation(relation):
node_type=LogicalPlanStepType.FunctionDataset, function="VALUES"
)
values_step.alias = subquery["alias"]["name"]["value"]
values_step.columns = tuple(col["value"] for col in subquery["alias"]["columns"])
values_step.columns = tuple(
col["name"]["value"] for col in subquery["alias"]["columns"]
)
values_step.values = [
tuple(logical_planner_builders.build(value) for value in row)
for row in subquery["subquery"]["body"]["Values"]["rows"]
Expand Down Expand Up @@ -731,7 +733,7 @@ def create_node_relation(relation):
function_step.args = [
logical_planner_builders.build(arg) for arg in function["args"]["args"]
]
function_step.columns = tuple(col["value"] for col in function["alias"]["columns"])
function_step.columns = tuple(col["name"]["value"] for col in function["alias"]["columns"])

step_id = random_string()
sub_plan.add_node(step_id, function_step)
Expand Down Expand Up @@ -989,7 +991,7 @@ def plan_show_columns(statement):
plan = LogicalPlan()

from_step = LogicalPlanNode(node_type=LogicalPlanStepType.Scan)
table = statement[root_node]["table_name"]
table = statement[root_node]["show_options"]["show_in"]["parent_name"]
from_step.relation = ".".join(part["value"] for part in table)
from_step.alias = from_step.relation
from_step.start_date = table[0].get("start_date")
Expand All @@ -1005,8 +1007,9 @@ def plan_show_columns(statement):
plan.add_node(step_id, show_step)
plan.add_edge(previous_step_id, step_id)

_filter = statement[root_node]["filter"]
_filter = statement[root_node]["show_options"].get("filter_position")
if _filter:
_filter = _filter["Suffix"]
filter_node = LogicalPlanNode(node_type=LogicalPlanStepType.Filter)
filter_node.condition = extract_simple_filter(_filter, "name")
previous_step_id, step_id = step_id, random_string()
Expand Down
4 changes: 2 additions & 2 deletions tests/sql_battery/test_shapes_and_errors_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1705,8 +1705,8 @@
("SELECT FLOOR(3.14159, 2) as floor_value", 1, 1, None),
("SELECT CEIL(3.14159, 0) as ceil_value", 1, 1, None),
("SELECT FLOOR(3.14159, 0) as floor_value", 1, 1, None),
("SELECT CEIL(3.14159, -1) as ceil_value", 1, 1, SqlError),
("SELECT FLOOR(3.14159, -1) as floor_value", 1, 1, SqlError),
("SELECT CEIL(3.14159, -1) as ceil_value", 1, 1, None),
("SELECT FLOOR(3.14159, -1) as floor_value", 1, 1, None),
("SELECT UPPER(name) FROM $planets", 9, 1, None),
("SELECT LOWER(name) FROM $astronauts WHERE UPPER(name) LIKE 'A%'", 11, 1, None),
("SELECT REVERSE(name) FROM $planets", 9, 1, None),
Expand Down

0 comments on commit 570f50c

Please sign in to comment.