Source:
public Expression visitLeave(ArrayConstructorNode node, List<Expression> children) throws SQLException { ArrayConstructorExpression arrayExpression = new ArrayConstructorExpression( children); for (int i = 0; i < children.size(); i++) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData( (BindParseNode) childNode, arrayExpression); } } boolean isLiteralExpression = true; for (Expression child:children) { isLiteralExpression&=(child instanceof LiteralExpression); } if (isLiteralExpression) { Object[] elements = new Object[children.size()]; PDataType elementType = null; for (int i = 0; i < children.size(); i++) { LiteralExpression literalExpression = (LiteralExpression)children.get(i); elements[i] = literalExpression.getValue(); if (literalExpression.getDataType() != null & literalExpression.getDataType() != elementType) { elementType = literalExpression.getDataType(); } } PDataType baseType = PDataType.fromTypeId(elementType.getSqlType()); Object value = PArrayDataType.instantiatePhoenixArray(baseType, elements); return LiteralExpression.newConstant(value, arrayExpression.getDataType()); } return wrapGroupByExpression(arrayExpression); }

Target:
public Expression visitLeave(ArrayConstructorNode node, List<Expression> children) throws SQLException { boolean isChildTypeUnknown = false; PDataType arrayElemDataType = children.get(0).getDataType(); for (int i = 0; i < children.size(); i++) { Expression child = children.get(i); PDataType childType = child.getDataType(); if (childType == null) { isChildTypeUnknown = true; } else if (arrayElemDataType == null) { arrayElemDataType = childType; isChildTypeUnknown = true; } else if (arrayElemDataType == childType || childType.isCoercibleTo(arrayElemDataType)) { continue; } else if (arrayElemDataType.isCoercibleTo(childType)) { arrayElemDataType = childType; } else { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CONVERT_TYPE) .setMessage( "Case expressions must have common type: " + arrayElemDataType + " cannot be coerced to " + childType).build().buildException(); } } if (isChildTypeUnknown && arrayElemDataType != null && arrayElemDataType.isCoercibleTo(PDataType.DECIMAL)) { arrayElemDataType = PDataType.DECIMAL; } ImmutableBytesWritable ptr = context.getTempPtr(); Object[] elements = new Object[children.size()]; if (node.isStateless()) { for (int i = 0; i < children.size(); i++) { Expression child = children.get(i); child.evaluate(null, ptr); Object value = arrayElemDataType.toObject(ptr, child.getDataType(), child.getColumnModifier()); elements[i] = LiteralExpression.newConstant(value, child.getDataType()).getValue(); } Object value = PArrayDataType.instantiatePhoenixArray(arrayElemDataType, elements); return LiteralExpression.newConstant(value, PDataType.fromTypeId(arrayElemDataType.getSqlType() + Types.ARRAY)); } else { ArrayConstructorExpression arrayExpression = new ArrayConstructorExpression(children, arrayElemDataType); for (int i = 0; i < children.size(); i++) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, arrayExpression); } } return arrayExpression; } }