/** * Parses the value for a ColumnValue using the separated array and scalar attributes. * * @param column The protobuf ColumnValue object * @return The parse value for this column */ static Object parseColumn(Common.ColumnValue column) { // Verify that we have one or the other (scalar or array) validateColumnValue(column); if (!column.hasField(SCALAR_VALUE_DESCRIPTOR)) { // The column in this row is an Array (has multiple values) List<Object> array = new ArrayList<>(column.getArrayValueCount()); for (Common.TypedValue arrayValue : column.getArrayValueList()) { // Duplicative because of the ColumnValue/TypedValue difference. if (Common.Rep.ARRAY == arrayValue.getType()) { // Each element in this Array is an Array. array.add(parseArray(arrayValue)); } else { // The array element is a scalar. array.add(deserializeScalarValue(arrayValue)); } } return array; } else { // Scalar return deserializeScalarValue(column.getScalarValue()); } }
/** * Parses the value for a ColumnValue using the separated array and scalar attributes. * * @param column The protobuf ColumnValue object * @return The parse value for this column */ static Object parseColumn(Common.ColumnValue column) { // Verify that we have one or the other (scalar or array) validateColumnValue(column); if (!column.hasField(SCALAR_VALUE_DESCRIPTOR)) { // The column in this row is an Array (has multiple values) List<Object> array = new ArrayList<>(column.getArrayValueCount()); for (Common.TypedValue arrayValue : column.getArrayValueList()) { // Duplicative because of the ColumnValue/TypedValue difference. if (Common.Rep.ARRAY == arrayValue.getType()) { // Each element in this Array is an Array. array.add(parseArray(arrayValue)); } else { // The array element is a scalar. array.add(deserializeScalarValue(arrayValue)); } } return array; } else { // Scalar return deserializeScalarValue(column.getScalarValue()); } }
/** * Parses the value for a ColumnValue using the separated array and scalar attributes. * * @param column The protobuf ColumnValue object * @return The parse value for this column */ static Object parseColumn(Common.ColumnValue column) { // Verify that we have one or the other (scalar or array) validateColumnValue(column); if (!ProtobufService.hasField(column, column.getDescriptorForType(), Common.ColumnValue.SCALAR_VALUE_FIELD_NUMBER)) { // Array List<Object> array = new ArrayList<>(column.getArrayValueCount()); for (Common.TypedValue arrayValue : column.getArrayValueList()) { array.add(getScalarValue(arrayValue)); } return array; } else { // Scalar return getScalarValue(column.getScalarValue()); } }
@Test public void testMalformedColumnValue() { // Invalid ColumnValue: has an array and scalar final ColumnValue bothAttributesColumnValue = ColumnValue.newBuilder().setHasArrayValue(true) .setScalarValue(NUMBER_VALUE).build(); // Note omission of setScalarValue(TypedValue). final ColumnValue neitherAttributeColumnValue = ColumnValue.newBuilder().setHasArrayValue(false) .build(); try { Frame.validateColumnValue(bothAttributesColumnValue); fail("Validating the ColumnValue should have failed as it has an array and scalar"); } catch (IllegalArgumentException e) { // Pass } try { Frame.validateColumnValue(neitherAttributeColumnValue); fail("Validating the ColumnValue should have failed as it has neither an array nor scalar"); } catch (IllegalArgumentException e) { // Pass } }
@Test public void testMalformedColumnValue() { // Invalid ColumnValue: has an array and scalar final ColumnValue bothAttributesColumnValue = ColumnValue.newBuilder().setHasArrayValue(true) .setScalarValue(NUMBER_VALUE).build(); // Note omission of setScalarValue(TypedValue). final ColumnValue neitherAttributeColumnValue = ColumnValue.newBuilder().setHasArrayValue(false) .build(); try { Frame.validateColumnValue(bothAttributesColumnValue); fail("Validating the ColumnValue should have failed as it has an array and scalar"); } catch (IllegalArgumentException e) { // Pass } try { Frame.validateColumnValue(neitherAttributeColumnValue); fail("Validating the ColumnValue should have failed as it has neither an array nor scalar"); } catch (IllegalArgumentException e) { // Pass } }
@Test public void testMalformedColumnValue() { // Invalid ColumnValue: has an array and scalar final ColumnValue bothAttributesColumnValue = ColumnValue.newBuilder().setHasArrayValue(true) .setScalarValue(NUMBER_VALUE).build(); // Note omission of setScalarValue(TypedValue). final ColumnValue neitherAttributeColumnValue = ColumnValue.newBuilder().setHasArrayValue(false) .build(); try { Frame.validateColumnValue(bothAttributesColumnValue); fail("Validating the ColumnValue should have failed as it has an array and scalar"); } catch (IllegalArgumentException e) { // Pass } try { Frame.validateColumnValue(neitherAttributeColumnValue); fail("Validating the ColumnValue should have failed as it has neither an array nor scalar"); } catch (IllegalArgumentException e) { // Pass } }