Skip to content

add SQL support for tinyint and all unsigned INTs - #3309

Closed
kmitchener wants to merge 29 commits into
apache:masterfrom
kmitchener:3307-support-tinyint-and-friends
Closed

add SQL support for tinyint and all unsigned INTs #3309
kmitchener wants to merge 29 commits into
apache:masterfrom
kmitchener:3307-support-tinyint-and-friends

Conversation

@kmitchener

@kmitchenerkmitchener commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes#3307 and closes#3325.

Rationale for this change

What changes are included in this PR?

Per the issue, this adds the following SQL datatype support:

  • TINYINT
  • UNSIGNED {TINYINT, SMALLINT, INT, BIGINT}

so now you can use this in create external table (c1 tinyint, c2 bigint unsigned) ... etc. Also available in cast() SQL:

select1::smallint unsigned;
select1::tinyint;
-- etc

Are there any user-facing changes?

remove make_data_type function in favor of convert_simple_data_type function because that one is pub
modify tests to use tinyint
add test for tinyint
@github-actionsgithub-actionsBot added core Core DataFusion crate sql SQL Planner labels Aug 31, 2022
@kmitchener

Copy link
Copy Markdown
ContributorAuthor

@alamb@andygrove what do you think about adding unsigned int support per #3307 here vs. a separate PR? Also, in general is unsigned int support via SQL desired?

Also, note that I removed what was almost a duplicate function in planner.rs -- now it will use the same function to convert SQL datatypes to Arrow datatypes for both SQL CAST() function and for the schema that can be specified for CREATE EXTERNAL TABLE. I'd just like to verify with someone more knowledgeable than me that this is a good change.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Merging #3309 (ee801bd) into master (312a7dd) will increase coverage by 0.04%.
The diff coverage is 97.67%.

@@ Coverage Diff @@## master #3309 +/- ##
==========================================
+ Coverage 85.74% 85.79% +0.04% 
==========================================
Files 294 295 +1 Lines 53749 53768 +19 ==========================================
+ Hits 46089 46132 +43 + Misses 7660 7636 -24 
Impacted FilesCoverage Δ
datafusion/core/tests/sql/mod.rs97.77% <ø> (ø)
datafusion/sql/src/planner.rs81.74% <88.88%> (+1.11%)⬆️
datafusion/core/tests/sql/cast.rs100.00% <100.00%> (ø)
datafusion/core/tests/sql/explain_analyze.rs83.39% <100.00%> (ø)
datafusion/expr/src/logical_plan/plan.rs77.88% <0.00%> (-0.50%)⬇️
datafusion/expr/src/utils.rs90.74% <0.00%> (-0.37%)⬇️
datafusion/optimizer/src/projection_push_down.rs98.06% <0.00%> (ø)
...fusion/optimizer/src/single_distinct_to_groupby.rs98.22% <0.00%> (ø)
...usion/optimizer/src/decorrelate_scalar_subquery.rs
...atafusion/optimizer/src/scalar_subquery_to_join.rs93.07% <0.00%> (ø)
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like a really nice PR @kmitchener -- thank you

CREATE EXTERNAL TABLE aggregate_test_100 (
c1 VARCHAR NOT NULL,
c2 INT NOT NULL,
c2 TINYINT NOT NULL,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for anyone else wondering, c8 is still a INT column

SQLDataType::Binary(_) => Ok(DataType::Binary),
SQLDataType::Bytea => Ok(DataType::Binary),
other => Err(DataFusionError::NotImplemented(format!(
// Explicitly list all other types so that if sqlparser

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is a nice refactor to remove duplication

@kmitchener

Copy link
Copy Markdown
ContributorAuthor

I've added the unsigned ints to this PR as well, matching what's in the issue

@kmitchener
kmitchener marked this pull request as ready for review August 31, 2022 19:51
@kmitchenerkmitchener changed the title add tinyint SQL supportadd SQL support for tinyint and all unsigned INTs Aug 31, 2022
@kmitchener
kmitchener requested a review from alambAugust 31, 2022 20:00

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great to me -- thank you @kmitchener

| `REAL` | `Float32` |
| `DOUBLE` | `Float64` |
| `DECIMAL(p,s)` | `Decimal128(p,s)` |
| SQL DataType | Arrow DataType |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👌 Thank you

@liukun4515

liukun4515 commented Sep 1, 2022

Copy link
Copy Markdown
Contributor

Please hold this pr, I want to review it and has concern about the data type supported in the SQL level.
@alamb@kmitchener

@liukun4515

Copy link
Copy Markdown
Contributor

I think the signed value is ok for me like small int, but the unsigned value make me concern about the compatibility and consistent behavior with other database system like spark https://spark.apache.org/docs/latest/sql-ref-datatypes.html#data-types

@liukun4515

Copy link
Copy Markdown
Contributor

I've added the unsigned ints to this PR as well, matching what's in the issue

I have the opposite opinion for supporting the unsigned value in SQL Level now.

You can fill a new issue to discuss about this, I think this is big change for API and interface which is not compatible with other database or SQL system.

@alamb

alamb commented Sep 1, 2022

Copy link
Copy Markdown
Contributor

Hi @liukun4515 -- thank you for the review. I will mark this PR as a draft while we discuss.

So that I can file the correct issue for discussion, can you help me understand what the concern is? Do you think:

  1. DataFusion should not support UNSIGNED INT
  2. DataFusion should treat SQL UNSIGNED INT as Int64
  3. Something else?

Thanks!

@alamb
alamb marked this pull request as draft September 1, 2022 12:06
@kmitchener

Copy link
Copy Markdown
ContributorAuthor

I've added the unsigned ints to this PR as well, matching what's in the issue

I have the opposite opinion for supporting the unsigned value in SQL Level now.

You can fill a new issue to discuss about this, I think this is big change for API and interface which is not compatible with other database or SQL system.

Sure thing -- it's in #3325.

Comment threaddatafusion/core/tests/sql/cast.rs Outdated
kmitchenerand others added 9 commits September 4, 2022 09:09
* rename DecorrelateScalarSubquery to ScalarSubqueryToJoin
* cargo fmt
* fix name and ref
* Add Aggregate::try_new with validation checks
* fix calculation of number of grouping expressions
* use suggested error message
* MINOR: add github action trigger
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
* Update .github/workflows/rust.yml
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
…ions (apache#3320)
* add inlist test for optimizer rule PreCastLitInComparisonExpressions
* fmt code
…pache#3336)
* Update signature for Expr.name so that schema is no longer required
* remove some duplicate code
* clippy
HaoYang670and others added 17 commits September 4, 2022 10:04
* update both year and month
Signed-off-by: remzi <13716567376yh@gmail.com>
* fmt
Signed-off-by: remzi <13716567376yh@gmail.com>
Signed-off-by: remzi <13716567376yh@gmail.com>
* impl binary ops between binary arrays and scalars
* impl binary ops between binary arrays and scalars
* run fmt
* add binary array input support in digest functions
* remove wrong input typecheck for digest functions
* fix digest function signatures
* add test for binary equality
* fix signature of trim function
* run fmt
* fix digest function signature, run fmt
* Add to_raw_logical_plan
* rename the new func
* change func name to to_unoptimized_plan
* add helper function for pop_expr
* remove unwraps
…apache#3348)
* MINOR: add df.to_unoptimized_plan() to docs, remove erroneous comment
* npx prettier
* add initial support for 'drop view'
* add tests
* add very basic docs
* add example to drop view doc
* ran prettier on the doc
* refactored, now done
* removed typo
* fix bad resolve merge conflict
…#3282)
* Add failing union_all_on_projection test
* Update projection step to replace both qualified and unqualified columns
* Remove redundant clone
Bumps [lz4-sys](https://github.com/10xGenomics/lz4-rs) from 1.9.3 to 1.9.4.
- [Release notes](https://github.com/10xGenomics/lz4-rs/releases)
- [Changelog](https://github.com/10XGenomics/lz4-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/10xGenomics/lz4-rs/commits)
---
updated-dependencies:
- dependency-name: lz4-sys
dependency-type: indirect
...
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* [MINOR] Add debug logging to plan teardown
* clippy
* add binary support
Signed-off-by: remzi <13716567376yh@gmail.com>
* support inset and add tests
Signed-off-by: remzi <13716567376yh@gmail.com>
* clean
Signed-off-by: remzi <13716567376yh@gmail.com>
* fmt
Signed-off-by: remzi <13716567376yh@gmail.com>
Signed-off-by: remzi <13716567376yh@gmail.com>
@github-actionsgithub-actionsBot added logical-expr Logical plan and expressions optimizer Optimizer rules physical-expr Changes to the physical-expr crates labels Sep 4, 2022
@kmitchener

Copy link
Copy Markdown
ContributorAuthor

I've really messed up this branch. Going to come back to this when brain works.

@kmitchener
kmitchener deleted the 3307-support-tinyint-and-friends branch September 5, 2022 12:02
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion cratelogical-exprLogical plan and expressionsoptimizerOptimizer rulesphysical-exprChanges to the physical-expr cratessqlSQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add SQL support for unsigned integers add SQL support for tinyint and unsigned versions of all INTs

11 participants

@kmitchener@codecov-commenter@liukun4515@alamb@andygrove@waynexia@HaoYang670@ozgrakkurt@chloeandmargaret@nvartolomei@jonmmease