Skip to content

fix complex types returning UNKNOWN as their SQL type inference#16216

Merged
zachjsh merged 4 commits intoapache:masterfrom
zachjsh:fix-complex-types-sql-type-inference
Apr 2, 2024
Merged

fix complex types returning UNKNOWN as their SQL type inference#16216
zachjsh merged 4 commits intoapache:masterfrom
zachjsh:fix-complex-types-sql-type-inference

Conversation

@zachjsh
Copy link
Copy Markdown
Contributor

@zachjsh zachjsh commented Mar 28, 2024

Description

Fixes issue where several aggregators are returning UNKNOWN or OTHER as their SQL type inference. Fixing this will allow these types do be validated against when defined as column on tables stored in the catalog.

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

);
}

public static SqlReturnTypeInference complexReturnTypeWithNullability(ColumnType columnType, boolean nullable)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: there are some SqlReturnTypeInference defined in Calcites, maybe this should also live there (or those should live here?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Moved.

.operandTypes(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)
.returnTypeNonNull(SqlTypeName.OTHER)
.returnTypeInference(
OperatorConversions.complexReturnTypeWithNullability(SketchModule.BUILD_TYPE, false))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i guess the changes to ComplexSqlType make this not really matter anymore, but technically THETA_SKETCH is the type string for what gets stored in columns and is associated with the serde that is common between build/merge (and the postagg the function maps to is actually using the merge type as its output type)

also, nit formatting, trailing ) should be on newline (though style stuff doesn't always flag this consistently). same formatting nit for other similar operator function changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks fixed, and think I got all the formatting ones, let me know if I missed any.

.operandTypes(SqlTypeFamily.ANY, SqlTypeFamily.EXACT_NUMERIC)
.returnTypeNonNull(SqlTypeName.OTHER)
.returnTypeInference(
OperatorConversions.complexReturnTypeWithNullability(HllSketchModule.TYPE, false))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should be DoublesSketchModule.DOUBLES_SKETCH i think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed

.operandTypes(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER)
.requiredOperandCount(1)
.returnTypeNonNull(SqlTypeName.OTHER)
.returnTypeInference(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this function returns ARRAY<DOUBLE> as far as I can tell. I think there is a .returnTypeNullableArrayWithNullableElements that can be used instead of .returnTypeInference

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed

public static final SqlReturnTypeInference
ARG1_NULLABLE_ARRAY_RETURN_TYPE_INFERENCE = new Arg1NullableArrayTypeInference();

public static SqlReturnTypeInference complexReturnTypeWithNullability(ColumnType columnType, boolean nullable)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zachjsh zachjsh merged commit 9b52c90 into apache:master Apr 2, 2024
@zachjsh zachjsh deleted the fix-complex-types-sql-type-inference branch April 2, 2024 18:36
@adarshsanjeev adarshsanjeev added this to the 30.0.0 milestone May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants