-
Notifications
You must be signed in to change notification settings - Fork 39
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 schema construction DSL #569
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some initial thoughts! If we're really headed for readable schema construction, Arrow C++-like constructors (e.g., int32("field name")
) are more likely to be what we want (and might be substantially less complicated to implement). I probably would have gone towards templating on ArrowType
and using our C library constructors instead of introducing another way to create schemas.
It's worth looking at how https://github.com/man-group/sparrow does this (I think they have something pretty similar to construct types/schemas).
I was hoping to merge #561 before adding anything to the testing library (it could use a review!).
@@ -2916,6 +2916,140 @@ class TestingJSONComparison { | |||
|
|||
/// @} | |||
|
|||
namespace dsl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe factory
?
/// \brief An alias to express a sequence of key value pairs. | ||
/// | ||
/// Each pair is a string formatted like "key=value". | ||
using metadata = std::vector<std::string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would std::vector<std::pair<std::string, std::string>>
work? I'm not sure the world is clamouring to create metadata keys that contain the =
symbol but it seems like it would be nice to avoid string parsing if we can.
schema{children{ | ||
{"i", "int32 field name", | ||
metadata{ | ||
"some_key=some_value", | ||
}}, | ||
{"i", dictionary{"u"}, "dictionary field name", | ||
metadata{ | ||
"some_key=some_value", | ||
}, | ||
ARROW_FLAG_NULLABLE}, | ||
}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In tests I think I would still prefer to see the C calls (but perhaps this is not where you were headed with this)
Construct
nanoarrow::UniqueSchema
s with a tiny C++ DSL:The python-equivalent signature is approximately:
After the first two arguments, all the rest can be provided in any order.