@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 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; }
/** * For Calcite 1.5, we made the mistake of using array length to determine when the value for a * column is a scalar or an array. This method performs the old parsing for backwards * compatibility. * * @param column The protobuf ColumnValue object * @return The parsed value for this column */ static Object parseOldStyleColumn(Common.ColumnValue column) { if (column.getValueCount() > 1) { List<Object> array = new ArrayList<>(column.getValueCount()); for (Common.TypedValue columnValue : column.getValueList()) { array.add(getScalarValue(columnValue)); } return array; } else { return getScalarValue(column.getValue(0)); } }
@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); }
/** * For Calcite 1.5, we made the mistake of using array length to determine when the value for a * column is a scalar or an array. This method performs the old parsing for backwards * compatibility. * * @param column The protobuf ColumnValue object * @return The parsed value for this column */ static Object parseOldStyleColumn(Common.ColumnValue column) { if (column.getValueCount() > 1) { List<Object> array = new ArrayList<>(column.getValueCount()); for (Common.TypedValue columnValue : column.getValueList()) { array.add(deserializeScalarValue(columnValue)); } return array; } else { return deserializeScalarValue(column.getValue(0)); } }
@Test public void testDeprecatedValueAttributeForScalars() { // Create a row with schema: [VARCHAR, INTEGER, DATE] List<Object> rows = Collections.<Object>singletonList(new Object[] {"string", Integer.MAX_VALUE, new Date().getTime()}); 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(); assertEquals(3, protoColumns.size()); // Verify that the scalar value is also present in the deprecated values attributes. List<Common.TypedValue> deprecatedValues = protoColumns.get(0).getValueList(); assertEquals(1, deprecatedValues.size()); Common.TypedValue scalarValue = protoColumns.get(0).getScalarValue(); assertEquals(deprecatedValues.get(0), scalarValue); }
@Test public void testDeprecatedValueAttributeForScalars() { // Create a row with schema: [VARCHAR, INTEGER, DATE] List<Object> rows = Collections.<Object>singletonList(new Object[] {"string", Integer.MAX_VALUE, new Date().getTime()}); 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(); assertEquals(3, protoColumns.size()); // Verify that the scalar value is also present in the deprecated values attributes. List<Common.TypedValue> deprecatedValues = protoColumns.get(0).getValueList(); assertEquals(1, deprecatedValues.size()); Common.TypedValue scalarValue = protoColumns.get(0).getScalarValue(); assertEquals(deprecatedValues.get(0), scalarValue); }
/** * For Calcite 1.5, we made the mistake of using array length to determine when the value for a * column is a scalar or an array. This method performs the old parsing for backwards * compatibility. * * @param column The protobuf ColumnValue object * @return The parsed value for this column */ static Object parseOldStyleColumn(Common.ColumnValue column) { if (column.getValueCount() > 1) { List<Object> array = new ArrayList<>(column.getValueCount()); for (Common.TypedValue columnValue : column.getValueList()) { array.add(deserializeScalarValue(columnValue)); } return array; } else { return deserializeScalarValue(column.getValue(0)); } }