yukkit opened a new pull request, #8143:
URL: https://github.com/apache/arrow-datafusion/pull/8143
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Closes #7923 .
Current Pull Request is an Experimental Demo for Validating the Feasibility
of Logical Types
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
## Features
- Create User-Defined Types (UDTs) through SQL, specifying the field types
as UDTs during table creation.
- Support the use of `UDT` as a function signature in `udf/udaf`.
- Register extension types through the `register_data_type` function in the
`SessionContext`.
## New Additions
- `LogicalType` struct.
- `ExtensionType` trait. Abstraction for extension types.
- `TypeSignature` struct. Uniquely identifies a data type.
## Major Changes
- Added `get_data_type(&self, _name: &TypeSignature) -> Option<LogicalType>`
function to the `ContextProvider` trait.
- In `DFSchema`, `DFField` now uses `LogicalType`, removing arrow `Field`
and retaining only `data_type`, `nullable`, `metadata` since `dict_id`,
`dict_is_ordered` are not necessary at the logical stage.
- `ExprSchemable` and `ExprSchema` now use `LogicalType`.
- `ast` to logical plan conversion now uses `LogicalType`.
## To Be Implemented
- `TypeCoercionRewriter` in the analyze stage uses logical types. For
example, functions like `comparison_coercion`, `get_input_types`,
`get_valid_types`, etc.
- Functions signatures for `udf/udaf` use `TypeSignature` instead of the
existing `DataType` for ease of use in `udf/udaf`.
## To Be Determined
- Should `ScalarValue` use `LogicalType` or arrow `DataType`?
- Should `TableSource` return `DFSchema` or arrow `Schema`?
* Still using `Schema`.
- Conversion between physical types and logical types (in Datafusion, type
conversion is achieved through the conversion of `DFSchema` to `Schema`;
logical plans use `DFSchema`, physical plans use `Schema`).
- Conversion between `Schema` and `DFSchema`
* When to convert `Schema` to `DFSchema`? During the construction of the
logical `TableScan` node, obtain arrow `Schema` through `TableSource` and then
convert it to `DFSchema`.
* When to convert `DFSchema` to `Schema`? Directly obtain arrow `Schema`
from `TableSource` in physical planner, no need for conversion.
## Some Thoughts
- In [this
comment](https://github.com/apache/arrow-rs/issues/4472#issuecomment-1749805039),
the use case of converting from `dyn Array` to `LineStringArray` or
`MultiPointArray` was raised. In my perspective, assuming there is a function
specifically designed for handling `LineString` data, the function signature
can be defined as `LineString`, ensuring that the input data must be of a type
acceptable by `LineStringArray`.
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]