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(query): to_binary function support variant, bitmap, geometry, geography types #17026

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

b41sh
Copy link
Member

@b41sh b41sh commented Dec 10, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

to_binary function support variant, bitmap, geometry and geography types.
These types of data are stored in binary format. We can use the to_binary function to determine whether the data format is correct, which is convenient for debugging.

for example

MySQL [(none)]> select try_to_binary(parse_json('{"data":"bend","test":100}')), try_to_binary(parse_json('[1,2,3]')), try_to_binary(parse_json('100'));
+----------------------------------------------------------------------+----------------------------------------------+----------------------------------+
| try_to_binary(parse_json('{"data":"bend","test":100}'))              | try_to_binary(parse_json('[1,2,3]'))         | try_to_binary(parse_json('100')) |
+----------------------------------------------------------------------+----------------------------------------------+----------------------------------+
| 4000000210000004100000041000000420000002646174617465737462656E645064 | 80000003200000022000000220000002500150025003 | 20000000200000025064             |
+----------------------------------------------------------------------+----------------------------------------------+----------------------------------+
1 row in set (0.056 sec)

MySQL [(none)]> SELECT try_to_binary(to_bitmap('100,200,300')), try_to_binary(to_bitmap('1,2,3,4,5'));
+----------------------------------------------------------------------+------------------------------------------------------------------------------+
| try_to_binary(to_bitmap('100,200,300'))                              | try_to_binary(to_bitmap('1,2,3,4,5'))                                        |
+----------------------------------------------------------------------+------------------------------------------------------------------------------+
| 0100000000000000000000003A3000000100000000000200100000006400C8002C01 | 0100000000000000000000003A30000001000000000004001000000001000200030004000500 |
+----------------------------------------------------------------------+------------------------------------------------------------------------------+
1 row in set (0.052 sec)

MySQL [(none)]> SELECT try_to_binary(st_geometryfromwkt('SRID=4326;POINT(1.0 2.0)')), try_to_binary(st_geometryfromwkt('SRID=4326;LINESTRING(1.0 2.0, 3.0 4.0, 10.1 11.2)'));
+---------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
| try_to_binary(st_geometryfromwkt('SRID=4326;POINT(1.0 2.0)')) | try_to_binary(st_geometryfromwkt('SRID=4326;LINESTRING(1.0 2.0, 3.0 4.0, 10.1 11.2)'))                                     |
+---------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
| 0101000020E6100000000000000000F03F0000000000000040            | 0102000020E610000003000000000000000000F03F00000000000000400000000000000840000000000000104033333333333324406666666666662640 |
+---------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.044 sec)

MySQL [(none)]> SELECT to_binary(st_geographyfromewkt('SRID=4326;POINT(-122.35 37.55)')), to_binary(st_geographyfromewkt('SRID=4326;LINESTRING(-122.35 37.5, -151.55 39.25)'));
+-------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
| to_binary(st_geographyfromewkt('SRID=4326;POINT(-122.35 37.55)')) | to_binary(st_geographyfromewkt('SRID=4326;LINESTRING(-122.35 37.5, -151.55 39.25)'))       |
+-------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
| 0101000020E61000006666666666965EC06666666666C64240                | 0102000020E6100000020000006666666666965EC00000000000C042409A99999999F162C00000000000A04340 |
+-------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
1 row in set (0.043 sec)
  • fixes: #[Link the issue here]

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Dec 10, 2024
@b41sh b41sh enabled auto-merge December 11, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants