/** * Verifies that a ColumnValue has only a scalar or array value, not both and not neither. * * @param column The protobuf ColumnValue object * @throws IllegalArgumentException When the above condition is not met */ static void validateColumnValue(Common.ColumnValue column) { final boolean hasScalar = column.hasField(SCALAR_VALUE_DESCRIPTOR); final boolean hasArrayValue = column.getHasArrayValue(); // These should always be different if (hasScalar == hasArrayValue) { throw new IllegalArgumentException("A column must have a scalar or array value, not " + (hasScalar ? "both" : "neither")); } }
/** * Verifies that a ColumnValue has only a scalar or array value, not both and not neither. * * @param column The protobuf ColumnValue object * @throws IllegalArgumentException When the above condition is not met */ static void validateColumnValue(Common.ColumnValue column) { final boolean hasScalar = column.hasField(SCALAR_VALUE_DESCRIPTOR); final boolean hasArrayValue = column.getHasArrayValue(); // These should always be different if (hasScalar == hasArrayValue) { throw new IllegalArgumentException("A column must have a scalar or array value, not " + (hasScalar ? "both" : "neither")); } }
if (other.getHasArrayValue() != false) { setHasArrayValue(other.getHasArrayValue());
if (other.getHasArrayValue() != false) { setHasArrayValue(other.getHasArrayValue());
if (other.getHasArrayValue() != false) { setHasArrayValue(other.getHasArrayValue());
@Test public void testNestedArraySerialization() { List<Object> rows = new ArrayList<>(); // [ "pk", [[1,2], [3,4]] ] rows.add(Arrays.asList("pk", Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)))); Frame frame = new Frame(0, true, rows); // Parse back the list in serialized form Common.Frame protoFrame = frame.toProto(); Common.Row protoRow = protoFrame.getRows(0); Common.ColumnValue protoColumn = protoRow.getValue(1); assertTrue(protoColumn.getHasArrayValue()); int value = 1; for (Common.TypedValue arrayElement : protoColumn.getArrayValueList()) { assertEquals(Common.Rep.ARRAY, arrayElement.getType()); for (Common.TypedValue nestedArrayElement : arrayElement.getArrayValueList()) { assertEquals(Common.Rep.INTEGER, nestedArrayElement.getType()); assertEquals(value++, nestedArrayElement.getNumberValue()); } } Frame newFrame = Frame.fromProto(protoFrame); @SuppressWarnings("unchecked") List<Object> newRow = (List<Object>) newFrame.rows.iterator().next(); @SuppressWarnings("unchecked") List<Object> expectedRow = (List<Object>) rows.get(0); assertEquals(expectedRow.get(0), newRow.get(0)); assertEquals(expectedRow.get(1), newRow.get(1)); } }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (getValueCount() > 0) { hash = (37 * hash) + VALUE_FIELD_NUMBER; hash = (53 * hash) + getValueList().hashCode(); } if (getArrayValueCount() > 0) { hash = (37 * hash) + ARRAY_VALUE_FIELD_NUMBER; hash = (53 * hash) + getArrayValueList().hashCode(); } hash = (37 * hash) + HAS_ARRAY_VALUE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean( getHasArrayValue()); if (hasScalarValue()) { hash = (37 * hash) + SCALAR_VALUE_FIELD_NUMBER; hash = (53 * hash) + getScalarValue().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Test public void testNestedArraySerialization() { List<Object> rows = new ArrayList<>(); // [ "pk", [[1,2], [3,4]] ] rows.add(Arrays.asList("pk", Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)))); Frame frame = new Frame(0, true, rows); // Parse back the list in serialized form Common.Frame protoFrame = frame.toProto(); Common.Row protoRow = protoFrame.getRows(0); Common.ColumnValue protoColumn = protoRow.getValue(1); assertTrue(protoColumn.getHasArrayValue()); int value = 1; for (Common.TypedValue arrayElement : protoColumn.getArrayValueList()) { assertEquals(Common.Rep.ARRAY, arrayElement.getType()); for (Common.TypedValue nestedArrayElement : arrayElement.getArrayValueList()) { assertEquals(Common.Rep.INTEGER, nestedArrayElement.getType()); assertEquals(value++, nestedArrayElement.getNumberValue()); } } Frame newFrame = Frame.fromProto(protoFrame); @SuppressWarnings("unchecked") List<Object> newRow = (List<Object>) newFrame.rows.iterator().next(); @SuppressWarnings("unchecked") List<Object> expectedRow = (List<Object>) rows.get(0); assertEquals(expectedRow.get(0), newRow.get(0)); assertEquals(expectedRow.get(1), newRow.get(1)); } }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (getValueCount() > 0) { hash = (37 * hash) + VALUE_FIELD_NUMBER; hash = (53 * hash) + getValueList().hashCode(); } if (getArrayValueCount() > 0) { hash = (37 * hash) + ARRAY_VALUE_FIELD_NUMBER; hash = (53 * hash) + getArrayValueList().hashCode(); } hash = (37 * hash) + HAS_ARRAY_VALUE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean( getHasArrayValue()); if (hasScalarValue()) { hash = (37 * hash) + SCALAR_VALUE_FIELD_NUMBER; hash = (53 * hash) + getScalarValue().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.calcite.avatica.proto.Common.ColumnValue)) { return super.equals(obj); } org.apache.calcite.avatica.proto.Common.ColumnValue other = (org.apache.calcite.avatica.proto.Common.ColumnValue) obj; boolean result = true; result = result && getValueList() .equals(other.getValueList()); result = result && getArrayValueList() .equals(other.getArrayValueList()); result = result && (getHasArrayValue() == other.getHasArrayValue()); result = result && (hasScalarValue() == other.hasScalarValue()); if (hasScalarValue()) { result = result && getScalarValue() .equals(other.getScalarValue()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@Test public void testDeprecatedValueAttributeForArrays() { // Create a row with schema: [VARCHAR, ARRAY] List<Object> rows = Collections.<Object>singletonList(new Object[] {"string", Arrays.asList(1, 2, 3)}); Meta.Frame frame = Meta.Frame.create(0, true, rows); // Convert it to a protobuf Common.Frame protoFrame = frame.toProto(); assertEquals(1, protoFrame.getRowsCount()); // Get that row we created Common.Row protoRow = protoFrame.getRows(0); // One row has many columns List<Common.ColumnValue> protoColumns = protoRow.getValueList(); // We should have two columns assertEquals(2, protoColumns.size()); // Fetch the ARRAY column Common.ColumnValue protoColumn = protoColumns.get(1); // We should have the 3 ARRAY elements in the array_values attribute as well as the deprecated // values attribute. List<Common.TypedValue> deprecatedValues = protoColumn.getValueList(); assertEquals(3, deprecatedValues.size()); assertTrue("Column 2 should have an array_value", protoColumns.get(1).getHasArrayValue()); List<Common.TypedValue> arrayValues = protoColumns.get(1).getArrayValueList(); assertEquals(arrayValues, deprecatedValues); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.calcite.avatica.proto.Common.ColumnValue)) { return super.equals(obj); } org.apache.calcite.avatica.proto.Common.ColumnValue other = (org.apache.calcite.avatica.proto.Common.ColumnValue) obj; boolean result = true; result = result && getValueList() .equals(other.getValueList()); result = result && getArrayValueList() .equals(other.getArrayValueList()); result = result && (getHasArrayValue() == other.getHasArrayValue()); result = result && (hasScalarValue() == other.hasScalarValue()); if (hasScalarValue()) { result = result && getScalarValue() .equals(other.getScalarValue()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@Test public void testDeprecatedValueAttributeForArrays() { // Create a row with schema: [VARCHAR, ARRAY] List<Object> rows = Collections.<Object>singletonList(new Object[] {"string", Arrays.asList(1, 2, 3)}); Meta.Frame frame = Meta.Frame.create(0, true, rows); // Convert it to a protobuf Common.Frame protoFrame = frame.toProto(); assertEquals(1, protoFrame.getRowsCount()); // Get that row we created Common.Row protoRow = protoFrame.getRows(0); // One row has many columns List<Common.ColumnValue> protoColumns = protoRow.getValueList(); // We should have two columns assertEquals(2, protoColumns.size()); // Fetch the ARRAY column Common.ColumnValue protoColumn = protoColumns.get(1); // We should have the 3 ARRAY elements in the array_values attribute as well as the deprecated // values attribute. List<Common.TypedValue> deprecatedValues = protoColumn.getValueList(); assertEquals(3, deprecatedValues.size()); assertTrue("Column 2 should have an array_value", protoColumns.get(1).getHasArrayValue()); List<Common.TypedValue> arrayValues = protoColumns.get(1).getArrayValueList(); assertEquals(arrayValues, deprecatedValues); }
/** * Verifies that a ColumnValue has only a scalar or array value, not both and not neither. * * @param column The protobuf ColumnValue object * @throws IllegalArgumentException When the above condition is not met */ static void validateColumnValue(Common.ColumnValue column) { final boolean hasScalar = ProtobufService.hasField(column, column.getDescriptorForType(), Common.ColumnValue.SCALAR_VALUE_FIELD_NUMBER); final boolean hasArrayValue = column.getHasArrayValue(); // These should always be different if (hasScalar == hasArrayValue) { throw new IllegalArgumentException("A column must have a scalar or array value, not " + (hasScalar ? "both" : "neither")); } }