Skip to content

Fixing return type for IPV4#15916

Merged
soumyava merged 4 commits intoapache:masterfrom
somu-imply:ipv4_null
Apr 4, 2024
Merged

Fixing return type for IPV4#15916
soumyava merged 4 commits intoapache:masterfrom
somu-imply:ipv4_null

Conversation

@somu-imply
Copy link
Copy Markdown
Contributor

@somu-imply somu-imply commented Feb 16, 2024

As shown here, the following query with ipv4_parse('1.2.3') returns a Calcite assertion instead of null when the string literal ‘1.2.3' can’t be parsed as an IP address.

select ipv4_parse('1.2.3') from (values(1)) as t(col)


Error: INVALID_INPUT

Calcite assertion violated: [Cannot add expression of different type to set: set type is RecordType(INTEGER NOT NULL EXPR$0) NOT NULL expression type is RecordType(INTEGER EXPR$0) NOT NULL set is rel#1354511:LogicalProject.NONE.[](input=HepRelVertex#1354510,exprs=[IPV4_PARSE('1.2.3')]) expression is LogicalProject(EXPR$0=[null:INTEGER]) LogicalValues(tuples=[[{ 1 }]]) Type mismatch: rowtype of original rel: RecordType(INTEGER NOT NULL EXPR$0) NOT NULL rowtype of new rel: RecordType(INTEGER EXPR$0) NOT NULL Difference: EXPR$0: INTEGER NOT NULL -> INTEGER ]

The reason was the return type was not set correctly. This PR fixes it.

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.

)
)
.returnTypeInference(ReturnTypes.BOOLEAN_NULLABLE)
.returnTypeNullable(SqlTypeName.BOOLEAN)
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.

should we add a test for this one too?

Copy link
Copy Markdown
Member

@clintropolis clintropolis Feb 24, 2024

Choose a reason for hiding this comment

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

actually, why is this wrong? does the method also return null if the subnet argument is not a valid address too?

if it does indeed need to change, does ipv6_match also need updated? https://github.com/apache/druid/blob/master/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/IPv6AddressMatchOperatorConversion.java#L50

Copy link
Copy Markdown
Contributor Author

@somu-imply somu-imply Feb 26, 2024

Choose a reason for hiding this comment

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

This does not need to be changed as ipv4_match even if 2nd arg is null throws a validation exception and does not return null in anyway. So I think it can be left out

@pranavbhole
Copy link
Copy Markdown
Contributor

@somu-imply Can we rebase and merge this ?

@soumyava soumyava merged commit 9729376 into apache:master Apr 4, 2024
@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.

5 participants