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

feat: add geometric data types and functions #543

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions extensions/functions_geometry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%YAML 1.2
---
types:
- name: geometry
structure: "BINARY"
# description: |
# An opaque type that can represent one or many points, lines, or shapes encompassing
# 2, 3 or 4 dimension.
scalar_functions:
-
name: "point"
description: >
Returns a 2D point with the given `x` and `y` coordinate values.
impls:
- args:
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
- name: x
value: fp64
- name: y
value: fp64
return: u!geometry
-
name: "makeline"
description: >
Returns a linestring connecting the endpoint of geometry `x` to the begin point of
geometry `y`. Repeated points at the beginning of input geometries are collapsed to a single point.

A linestring can be closed or simple. A closed linestring starts and ends on the same
point. A simple linestring does not cross or touch itself.
impls:
- args:
- name: x
value: u!geometry
- name: y
value: u!geometry
Comment on lines +31 to +34
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nitpick (and I also don't know if substrait has something like positional args where the actual name doesn't matter, in which case it is only for documentation): you might want to use different argument names than x and y, since naively that would easily be interpreted as x and y coordinates (like in point()), while here it's rather "point 1" and "point 2".
So I would rather go with something like geom1/geom2, or if preferring something generic, eg a/b

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh...I think I missed this when we decided to change to using the opaque geometry type. Thanks for catching this! I'm addressing it in the PR: https://github.com/substrait-io/substrait/pull/554/files

return: u!geometry
13 changes: 10 additions & 3 deletions site/docs/extensions/generate_function_docs.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#!/usr/bin/python3
# SPDX-License-Identifier: Apache-2.0

import filecmp
import os
import mkdocs_gen_files
import tempfile
from itertools import cycle
from pathlib import Path
import tempfile
import filecmp

import mkdocs_gen_files
import oyaml as yaml
from mdutils.mdutils import MdUtils


def write_markdown(file_obj: dict, file_name: str) -> None:
if "types" in file_obj:
custom_types = file_obj.pop("types")
mdFile.new_header(level=2, title="Data Types")
for type in custom_types:
for key, value in type.items():
mdFile.new_line(f"{key}: {value}")

for function_classification, value in file_obj.items():
function_classification_str = function_classification.replace("_", " ").title()
mdFile.new_header(level=2, title=f"{function_classification_str}")
Expand Down
Loading