Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 145
feat(backend/kernel): match Thrift backend's user-visible surface#793
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -85,24 +85,56 @@ def description_from_arrow_schema(schema: pyarrow.Schema) -> List[Tuple]: | ||
| """Build a PEP 249 ``description`` list from a pyarrow Schema. | ||
| Each tuple is ``(name, type_code, display_size, internal_size, | ||
| precision, scale, null_ok)``. ``null_ok`` is taken from | ||
| ``field.nullable``; the other four are not reported by the | ||
| kernel today. | ||
| precision, scale, null_ok)``. PEP 249 allows ``null_ok`` to be | ||
vikrantpuppala marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| either a bool or ``None``; the Thrift backend always reports | ||
| ``None``, so we match that here for drop-in parity. The actual | ||
| nullability bit is still available via ``schema.field(i).nullable`` | ||
| for callers that want it from the Arrow schema directly. | ||
| ``type_code`` normally comes from the Arrow ``DataType`` via | ||
| ``_arrow_type_to_dbapi_string``, which collapses | ||
| Databricks-specific types into their nearest Arrow shape (e.g. | ||
| ``VARIANT`` → ``Utf8``). To recover the precise Databricks type | ||
| name, we consult the field's metadata first — the kernel writes | ||
| the server-reported type into ``databricks.type_name`` (see | ||
| ``databricks_sql_kernel::reader::metadata_keys``). Today only | ||
| ``VARIANT`` is special-cased here for parity with the Thrift | ||
| backend's behaviour; other precise types (``INTERVAL_*``, | ||
| ``GEOMETRY``, ``GEOGRAPHY``) collapse to their Arrow shape on | ||
| both backends and don't need a remap. | ||
| """ | ||
| return [ | ||
| ( | ||
| field.name, | ||
| _arrow_type_to_dbapi_string(field.type), | ||
| _databricks_type_for_field(field), | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| field.nullable, | ||
| ) | ||
| for field in schema | ||
| ] | ||
| def _databricks_type_for_field(field: pyarrow.Field) -> str: | ||
| """Pick the PEP 249 type code for a single field. | ||
| Consults the field's Arrow metadata under | ||
| ``databricks.type_name`` (written by the kernel from the SEA | ||
| response's column type) so types that collapse onto a generic | ||
| Arrow shape can still be distinguished. Today only ``VARIANT`` | ||
| is mapped; everything else delegates to | ||
| ``_arrow_type_to_dbapi_string``. | ||
| """ | ||
| md = field.metadata or {} | ||
| # `databricks.type_name` is bytes (Arrow metadata is always | ||
| # bytes); compare against bytes to avoid one encode per field. | ||
| if md.get(b"databricks.type_name") == b"VARIANT": | ||
| return "variant" | ||
| return _arrow_type_to_dbapi_string(field.type) | ||
| def _tspark_param_value_str(param: ttypes.TSparkParameter) -> Any: | ||
| """Extract the string-encoded value from a ``TSparkParameter``, | ||
| or ``None`` for SQL NULL. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.