mihaibudiu commented on code in PR #3579:
URL: https://github.com/apache/calcite/pull/3579#discussion_r1428365291
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1061,23 +1061,29 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding
operatorBinding,
private static RelDataType arrayReturnType(SqlOperatorBinding opBinding) {
final List<RelDataType> operandTypes = opBinding.collectOperandTypes();
- // only numeric & character types check
+ // only numeric & character types check, this is a special spark array case
+ // the form like ARRAY(1, 2, '3') will return ["1", "2", "3"]
boolean hasNumeric = false;
boolean hasCharacter = false;
boolean hasOthers = false;
for (RelDataType type : operandTypes) {
SqlTypeFamily family = type.getSqlTypeName().getFamily();
- requireNonNull(family, "array element type family");
+ // some types such as Row, the family is null, fallback to normal
inferred type logic
+ if (family == null) {
+ hasOthers = true;
+ break;
+ }
+ // skip it because we allow NULL literal
+ if (SqlTypeUtil.isNull(type)) {
+ continue;
Review Comment:
Type families in Calcite are extremely confusing. I have filed a PR
https://github.com/apache/calcite/pull/3411 trying to clarify some of their
semantics, but that doesn't address all the issues. Unfortunately type families
are used pervasively so there is no way to remove them. One thing that makes
them confusing is that the SQL standard talks about type families, but the type
families in Calcite do not align with the standard. For example, in Calcite
DOUBLE has a type family of NUMERIC, whereas the standard says it should be
APPROXIMATE_NUMERIC. You will also notice that there are two kinds of families,
primary and secondary. Moreover, there are many types which do not have any
family, as in this example. I find that code which deals directly with types is
much clearer, as this example illustrates.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]