From 2aef6ac685d4fc147ffd9a7bf21a7dc7a551b67e Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Thu, 22 Aug 2024 13:36:43 -0700 Subject: [PATCH] fix ipv4_parse function return type in SQL to be bigint instead of integer (#16942) * fix ipv4_parse function return type in SQL to be bigint instead of integer * fix default value mode --- .../IPv4AddressParseOperatorConversion.java | 2 +- .../druid/sql/calcite/CalciteQueryTest.java | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/IPv4AddressParseOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/IPv4AddressParseOperatorConversion.java index 297f10c63ad..e4ad6e796b3 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/IPv4AddressParseOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/IPv4AddressParseOperatorConversion.java @@ -39,7 +39,7 @@ public class IPv4AddressParseOperatorConversion extends DirectOperatorConversion OperandTypes.family(SqlTypeFamily.STRING), OperandTypes.family(SqlTypeFamily.INTEGER) )) - .returnTypeNullable(SqlTypeName.INTEGER) + .returnTypeNullable(SqlTypeName.BIGINT) .functionCategory(SqlFunctionCategory.USER_DEFINED_FUNCTION) .build(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 7566d7f7786..556b437e758 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -16128,7 +16128,31 @@ public class CalciteQueryTest extends BaseCalciteQueryTest .resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST) .build() ), - ImmutableList.of(NullHandling.sqlCompatible() ? new Object[]{null} : new Object[]{0}) + ImmutableList.of(NullHandling.sqlCompatible() ? new Object[]{null} : new Object[]{0L}) + ); + } + + @Test + public void testIpv4ParseWithBigintOutput() + { + testQuery( + "select ipv4_parse('192.168.0.1') from (values(1)) as t(col)", + ImmutableList.of( + Druids.newScanQueryBuilder() + .dataSource(InlineDataSource.fromIterable( + ImmutableList.of(new Object[]{1L}), + RowSignature.builder() + .add("col", ColumnType.LONG) + .build() + )) + .intervals(querySegmentSpec(Filtration.eternity())) + .columns("v0") + .virtualColumns(expressionVirtualColumn("v0", "3232235521", ColumnType.LONG)) + .context(QUERY_CONTEXT_DEFAULT) + .resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST) + .build() + ), + ImmutableList.of(new Object[]{3232235521L}) ); }