Fixing return type for IPV4 (#15916)

* Fixing return type for IPV4

* Update ipv4match
This commit is contained in:
Soumyava 2024-04-04 08:49:50 -07:00 committed by GitHub
parent 75fb57ed6e
commit 972937659d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 2 deletions

View File

@ -23,8 +23,8 @@ import org.apache.calcite.sql.SqlFunction;
import org.apache.calcite.sql.SqlFunctionCategory;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;
import org.apache.calcite.sql.type.SqlTypeFamily;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.query.expression.IPv4AddressParseExprMacro;
import org.apache.druid.sql.calcite.expression.DirectOperatorConversion;
@ -39,7 +39,7 @@ public class IPv4AddressParseOperatorConversion extends DirectOperatorConversion
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.INTEGER)
))
.returnTypeInference(ReturnTypes.INTEGER_NULLABLE)
.returnTypeNullable(SqlTypeName.INTEGER)
.functionCategory(SqlFunctionCategory.USER_DEFINED_FUNCTION)
.build();

View File

@ -15509,4 +15509,45 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
)
);
}
@Test
public void testIpv4ParseWithNullableType()
{
testQuery(
"select ipv4_parse('1.2.3') from (values(1)) as t(col)",
NullHandling.sqlCompatible() ?
ImmutableList.of(
Druids.newScanQueryBuilder()
.dataSource(InlineDataSource.fromIterable(
ImmutableList.of(new Object[]{null}),
RowSignature.builder()
.add("EXPR$0", ColumnType.LONG)
.build()
))
.intervals(querySegmentSpec(Filtration.eternity()))
.columns("EXPR$0")
.context(QUERY_CONTEXT_DEFAULT)
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.legacy(false)
.build()
) :
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", "0", ColumnType.LONG))
.context(QUERY_CONTEXT_DEFAULT)
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.legacy(false)
.build()
),
ImmutableList.of(NullHandling.sqlCompatible() ? new Object[]{null} : new Object[]{0})
);
}
}