Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,14 @@ public ColumnValueSelector<?> makeColumnValueSelector(
return new ArrayElementColumnValueSelector(arraySelector, elementNumber);
}

// we are not a nested column and are being asked for a path that will never exist, so we are nil selector
return NilColumnValueSelector.instance();
if (holder.getCapabilities().isArray() || ColumnType.NESTED_DATA.equals(holder.getCapabilities().toColumnType())) {
// Not a root access and no specialized path available. But the underlying column is array or nested typed,
// so we may still be able to walk it using exprs. Try that.
return makeColumnValueSelectorUsingColumnSelectorFactory(selectorFactory);
} else {
// we are not a nested or array column, and are being asked for a path that will never exist, so nil selector
return NilColumnValueSelector.instance();
}
}

@Override
Expand Down Expand Up @@ -486,11 +492,11 @@ public VectorObjectSelector makeVectorObjectSelector(
final NestedVectorColumnSelectorFactory nestedColumnSelectorFactory =
column.as(NestedVectorColumnSelectorFactory.class);

if (isNestedColumn(holder)) {
if (isNestedColumn(holder) || holder.getCapabilities().isArray()) {
if (fieldSpec.processFromRaw || nestedTypeInspector == null || nestedColumnSelectorFactory == null) {
// 1) If processFromRaw is true, that means JSON_QUERY.
// 2) If no nestedTypeInspector, nestedColumnSelectorFactory then that means this is a nested type that is
// not exposed as a nested column.
// 2) If no nestedTypeInspector, nestedColumnSelectorFactory then that means this is a nested or array
// type that is not exposed as a nested column.
// Either way, we read and process raw objects.
return new RawFieldVectorObjectSelector(
selectorFactory.makeObjectSelector(fieldSpec.columnName),
Expand All @@ -499,7 +505,9 @@ public VectorObjectSelector makeVectorObjectSelector(
);
}
final ColumnType leastRestrictiveType = nestedTypeInspector.getFieldLogicalType(fieldSpec.parts);
if (leastRestrictiveType != null && leastRestrictiveType.isNumeric() && !Types.isNumeric(fieldSpec.expectedType)) {
if (leastRestrictiveType != null
&& leastRestrictiveType.isNumeric()
&& !Types.isNumeric(fieldSpec.expectedType)) {
return ExpressionVectorSelectors.castValueSelectorToObject(
offset,
columnName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ public NestedObjectVirtualColumn(
StringUtils.format(
"%s(%s)",
NestedDataExpressions.JsonObjectExprMacro.NAME,
keyExprMap.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(entry -> {
final String key = entry.getKey();
final TypedExpression valueExpr = entry.getValue();
return Parser.constant(key).stringify() + ',' + valueExpr.expression;
}).collect(Collectors.joining(","))
Preconditions.checkNotNull(keyExprMap, "object")
.entrySet().stream().map(entry -> {
final String key = entry.getKey();
final TypedExpression valueExpr = entry.getValue();
return Parser.constant(key).stringify() + ',' + valueExpr.expression;
}).collect(Collectors.joining(","))
),
ColumnType.NESTED_DATA,
macroTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class NestedObjectVirtualColumnTest
Expand All @@ -56,9 +55,10 @@ public void testSerde() throws JsonProcessingException
@Test
public void testGetKeyExprMap()
{
Map<String, NestedObjectVirtualColumn.TypedExpression> keyExprMap = new HashMap<>();
keyExprMap.put("key1", new NestedObjectVirtualColumn.TypedExpression("expr1", ColumnType.STRING));
keyExprMap.put("key2", new NestedObjectVirtualColumn.TypedExpression("expr2", ColumnType.DOUBLE));
Map<String, NestedObjectVirtualColumn.TypedExpression> keyExprMap = ImmutableMap.of(
"key1", new NestedObjectVirtualColumn.TypedExpression("expr1", ColumnType.STRING),
"key2", new NestedObjectVirtualColumn.TypedExpression("expr2", ColumnType.DOUBLE)
);

NestedObjectVirtualColumn column = new NestedObjectVirtualColumn(
"test_obj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,34 @@ FROM test_array;
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[0]' RETURNING boolean array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------+
| col |
+--------------+
| [1, 0, null] |
| [1, 0, null] |
| [null, 0, 1] |
| [null, 0, 1] |
+--------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C3_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][0]' RETURNING boolean array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------+
| col |
+--------------+
| [1, 0, null] |
| [1, 0, null] |
| [null, 0, 1] |
| [null, 0, 1] |
+--------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C4_D1
Expand All @@ -152,16 +170,34 @@ FROM test_array;
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[1]' RETURNING bigint array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------+
| col |
+--------------+
| [1, 2, null] |
| [1, 2, null] |
| [null, 2, 1] |
| [null, 2, 1] |
+--------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C6_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][1]' RETURNING bigint array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------+
| col |
+--------------+
| [1, 2, null] |
| [1, 2, null] |
| [null, 2, 1] |
| [null, 2, 1] |
+--------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C7_D1
Expand All @@ -185,16 +221,34 @@ FROM test_array;
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[2]' RETURNING decimal array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+------------------+
| col |
+------------------+
| [0.1, 0.2, null] |
| [0.1, 0.2, null] |
| [null, 0.2, 0.1] |
| [null, 0.2, 0.1] |
+------------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C9_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][2]' RETURNING decimal array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+------------------+
| col |
+------------------+
| [0.1, 0.2, null] |
| [0.1, 0.2, null] |
| [null, 0.2, 0.1] |
| [null, 0.2, 0.1] |
+------------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C10_D1
Expand All @@ -218,16 +272,34 @@ FROM test_array;
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[3]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+----------------+
| col |
+----------------+
| [S1, S2, null] |
| [S1, S2, null] |
| [null, S2, S1] |
| [null, S2, S1] |
+----------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C12_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][3]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+----------------+
| col |
+----------------+
| [S1, S2, null] |
| [S1, S2, null] |
| [null, S2, S1] |
| [null, S2, S1] |
+----------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C13_D1
Expand All @@ -251,16 +323,34 @@ FROM test_array;
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[4]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------------+
| col |
+--------------------+
| [null, null, null] |
| [null, null, null] |
| [null, null, null] |
| [null, null, null] |
+--------------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C15_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][4]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------------+
| col |
+--------------------+
| [null, null, null] |
| [null, null, null] |
| [null, null, null] |
| [null, null, null] |
+--------------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C16_D1
Expand All @@ -284,16 +374,34 @@ FROM test_array;
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[5]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+-----+
| col |
+-----+
| [] |
| [] |
| [] |
| [] |
+-----+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C18_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][5]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+-----+
| col |
+-----+
| [] |
| [] |
| [] |
| [] |
+-----+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C19_D1
Expand All @@ -317,16 +425,34 @@ FROM test_array;
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[6]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------------------+
| col |
+--------------------------+
| [null, S1, 0.1, 1, true] |
| [null, S1, 0.1, 1, true] |
| [true, 1, 0.1, S1, null] |
| [true, 1, 0.1, S1, null] |
+--------------------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C21_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][6]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+--------------------------+
| col |
+--------------------------+
| [null, S1, 0.1, 1, true] |
| [null, S1, 0.1, 1, true] |
| [true, 1, 0.1, S1, null] |
| [true, 1, 0.1, S1, null] |
+--------------------------+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C22_D1
Expand All @@ -341,14 +467,31 @@ Cannot apply 'MV_TO_ARRAY' to arguments of type 'MV_TO_ARRAY(
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+-----+
| col |
+-----+
| |
| |
| |
| |
+-----+
(4 rows)

!ok

#-------------------------------------------------------------------------
# TESTCASE: test_mv_funcs TEST_ID: A1_B16_C24_D1
#-------------------------------------------------------------------------
SELECT mv_to_array(json_value(a_nested, '$[7][7]' RETURNING varchar array)) AS col
FROM test_array;
should be an identifier expression. Use array() instead
!error
+-----+
| col |
+-----+
| |
| |
| |
| |
+-----+
(4 rows)

!ok
Loading