From 147c4985652edf7dd7de677f223242d7bea35f7c Mon Sep 17 00:00:00 2001 From: Nathan Ziebart Date: Mon, 16 Oct 2017 18:54:56 +0100 Subject: [PATCH 1/7] support persisters for v2 tables --- atlasdb-client/build.gradle | 3 + .../generated/SchemaApiTestTable.java | 44 +++---- .../generated/SchemaApiTestV2Table.java | 25 ++-- .../table/description/test/StringValue.java | 35 +++++ .../test/StringValuePersister.java | 29 +++++ .../description/ColumnValueDescription.java | 23 +++- .../table/description/TableDefinition.java | 7 + .../atlasdb/table/description/ValueType.java | 123 ++++++------------ .../table/description/render/Renderers.java | 10 +- .../render/TableClassRendererV2.java | 55 ++++---- .../description/AbstractSchemaApiTest.java | 34 +++-- .../table/description/ApiTestSchema.java | 7 +- .../table/description/SchemaApiTestImpl.java | 5 +- .../description/SchemaApiTestV2Impl.java | 5 +- docs/source/release_notes/release-notes.rst | 4 +- 15 files changed, 240 insertions(+), 169 deletions(-) create mode 100644 atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValue.java create mode 100644 atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValuePersister.java diff --git a/atlasdb-client/build.gradle b/atlasdb-client/build.gradle index bc6a3e460a9..462bb9e9a1c 100644 --- a/atlasdb-client/build.gradle +++ b/atlasdb-client/build.gradle @@ -74,4 +74,7 @@ dependencies { testCompile group: 'org.assertj', name: 'assertj-core' integrationInputCompile project(":atlasdb-client") + + integrationInputCompile group: 'org.immutables', name: 'value' + } diff --git a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java index 0c80b989526..071254ec9ae 100644 --- a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java +++ b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java @@ -292,18 +292,18 @@ public String toString() { /** *
      * Column value description {
-     *   type: String;
+     *   type: com.palantir.atlasdb.table.description.test.StringValue;
      * }
      * 
*/ - public static final class Column2 implements SchemaApiTestNamedColumnValue { - private final String value; + public static final class Column2 implements SchemaApiTestNamedColumnValue { + private final com.palantir.atlasdb.table.description.test.StringValue value; - public static Column2 of(String value) { + public static Column2 of(com.palantir.atlasdb.table.description.test.StringValue value) { return new Column2(value); } - private Column2(String value) { + private Column2(com.palantir.atlasdb.table.description.test.StringValue value) { this.value = value; } @@ -318,13 +318,13 @@ public String getShortColumnName() { } @Override - public String getValue() { + public com.palantir.atlasdb.table.description.test.StringValue getValue() { return value; } @Override public byte[] persistValue() { - byte[] bytes = PtBytes.toBytes(value); + byte[] bytes = com.palantir.atlasdb.compress.CompressionUtils.compress(new com.palantir.atlasdb.table.description.test.StringValuePersister().persistToBytes(value), com.palantir.atlasdb.table.description.ColumnValueDescription.Compression.NONE); return CompressionUtils.compress(bytes, Compression.NONE); } @@ -337,7 +337,7 @@ public byte[] persistColumnName() { @Override public Column2 hydrateFromBytes(byte[] bytes) { bytes = CompressionUtils.decompress(bytes, Compression.NONE); - return of(PtBytes.toString(bytes, 0, bytes.length-0)); + return of(new com.palantir.atlasdb.table.description.test.StringValuePersister().hydrateFromBytes(com.palantir.atlasdb.compress.CompressionUtils.decompress(bytes, com.palantir.atlasdb.table.description.ColumnValueDescription.Compression.NONE))); } }; @@ -404,7 +404,7 @@ public Long getColumn1() { return value.getValue(); } - public String getColumn2() { + public com.palantir.atlasdb.table.description.test.StringValue getColumn2() { byte[] bytes = row.getColumns().get(PtBytes.toCachedBytes("d")); if (bytes == null) { return null; @@ -422,10 +422,10 @@ public Long apply(SchemaApiTestRowResult rowResult) { }; } - public static Function getColumn2Fun() { - return new Function() { + public static Function getColumn2Fun() { + return new Function() { @Override - public String apply(SchemaApiTestRowResult rowResult) { + public com.palantir.atlasdb.table.description.test.StringValue apply(SchemaApiTestRowResult rowResult) { return rowResult.getColumn2(); } }; @@ -495,15 +495,15 @@ public Map getColumn1s(Collection rows return ret; } - public Map getColumn2s(Collection rows) { + public Map getColumn2s(Collection rows) { Map cells = Maps.newHashMapWithExpectedSize(rows.size()); for (SchemaApiTestRow row : rows) { cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("d")), row); } Map results = t.get(tableRef, cells.keySet()); - Map ret = Maps.newHashMapWithExpectedSize(results.size()); + Map ret = Maps.newHashMapWithExpectedSize(results.size()); for (Entry e : results.entrySet()) { - String val = Column2.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue(); + com.palantir.atlasdb.table.description.test.StringValue val = Column2.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue(); ret.put(cells.get(e.getKey()), val); } return ret; @@ -533,25 +533,25 @@ public void putColumn1UnlessExists(Map map) { putUnlessExists(Multimaps.forMap(toPut)); } - public void putColumn2(SchemaApiTestRow row, String value) { + public void putColumn2(SchemaApiTestRow row, com.palantir.atlasdb.table.description.test.StringValue value) { put(ImmutableMultimap.of(row, Column2.of(value))); } - public void putColumn2(Map map) { + public void putColumn2(Map map) { Map> toPut = Maps.newHashMapWithExpectedSize(map.size()); - for (Entry e : map.entrySet()) { + for (Entry e : map.entrySet()) { toPut.put(e.getKey(), Column2.of(e.getValue())); } put(Multimaps.forMap(toPut)); } - public void putColumn2UnlessExists(SchemaApiTestRow row, String value) { + public void putColumn2UnlessExists(SchemaApiTestRow row, com.palantir.atlasdb.table.description.test.StringValue value) { putUnlessExists(ImmutableMultimap.of(row, Column2.of(value))); } - public void putColumn2UnlessExists(Map map) { + public void putColumn2UnlessExists(Map map) { Map> toPut = Maps.newHashMapWithExpectedSize(map.size()); - for (Entry e : map.entrySet()) { + for (Entry e : map.entrySet()) { toPut.put(e.getKey(), Column2.of(e.getValue())); } putUnlessExists(Multimaps.forMap(toPut)); @@ -875,5 +875,5 @@ public List findConstraintFailuresNoRead(Map writes, * {@link UnsignedBytes} * {@link ValueType} */ - static String __CLASS_HASH = "r1lpoi0kpKMwjzfzxCBPow=="; + static String __CLASS_HASH = "fWhFhDMIHuO9N51DDthfNA=="; } diff --git a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestV2Table.java b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestV2Table.java index f2df1fd4f31..f00f9200831 100644 --- a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestV2Table.java +++ b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestV2Table.java @@ -13,6 +13,7 @@ import com.palantir.atlasdb.keyvalue.api.RangeRequest; import com.palantir.atlasdb.keyvalue.api.RowResult; import com.palantir.atlasdb.keyvalue.api.TableReference; +import com.palantir.atlasdb.table.description.test.StringValue; import com.palantir.atlasdb.table.generation.ColumnValues; import com.palantir.atlasdb.transaction.api.Transaction; import com.palantir.common.base.BatchingVisitableView; @@ -166,7 +167,7 @@ public LinkedHashMap getSmallRowRangeColumn1(RangeRequest rangeReq /** * Returns the value for column Column2 and specified row components. */ - public Optional getColumn2(String component1) { + public Optional getColumn2(String component1) { SchemaApiTestTable.SchemaApiTestRow row = SchemaApiTestTable.SchemaApiTestRow.of(component1); byte[] bytes = row.persistToBytes(); ColumnSelection colSelection = @@ -184,7 +185,7 @@ public Optional getColumn2(String component1) { * Returns a mapping from the specified row keys to their value at column Column2. * As the Column2 values are all loaded in memory, do not use for large amounts of data. * If the column does not exist for a key, the entry will be omitted from the map. */ - public Map getColumn2(Iterable rowKeys) { + public Map getColumn2(Iterable rowKeys) { ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d"))); List rows = Lists @@ -207,14 +208,14 @@ public Map getColumn2(Iterable rowKeys) { * Returns a mapping from all the row keys in a rangeRequest to their value at column Column2 * (if that column exists for the row-key). As the Column2 values are all loaded in memory, * do not use for large amounts of data. The order of results is preserved in the map. */ - public LinkedHashMap getSmallRowRangeColumn2(RangeRequest rangeRequest) { + public LinkedHashMap getSmallRowRangeColumn2(RangeRequest rangeRequest) { ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d"))); rangeRequest = rangeRequest.getBuilder().retainColumns(colSelection).build(); Preconditions.checkArgument(rangeRequest.getColumnNames().size() <= 1, "Must not request columns other than Column2."); - LinkedHashMap resultsMap = new LinkedHashMap<>(); + LinkedHashMap resultsMap = new LinkedHashMap<>(); BatchingVisitableView.of(t.getRange(tableRef, rangeRequest)) .immutableCopy().forEach(entry -> { SchemaApiTestTable.SchemaApiTestRowResult resultEntry = @@ -228,7 +229,7 @@ public LinkedHashMap getSmallRowRangeColumn2(RangeRequest rangeR * Returns a mapping from all the row keys in a range to their value at column Column2 * (if that column exists for the row-key). As the Column2 values are all loaded in memory, * do not use for large amounts of data. The order of results is preserved in the map. */ - public LinkedHashMap getSmallRowRangeColumn2(String startInclusive, + public LinkedHashMap getSmallRowRangeColumn2(String startInclusive, String endExclusive) { RangeRequest rangeRequest = RangeRequest.builder() .startRowInclusive(SchemaApiTestTable.SchemaApiTestRow.of(startInclusive).persistToBytes()) @@ -241,7 +242,7 @@ public LinkedHashMap getSmallRowRangeColumn2(String startInclusi * Returns a mapping from the first sizeLimit row keys in a rangeRequest to their value * at column Column2 (if that column exists). As the Column2 entries are all loaded in memory, * do not use for large values of sizeLimit. The order of results is preserved in the map. */ - public LinkedHashMap getSmallRowRangeColumn2(RangeRequest rangeRequest, + public LinkedHashMap getSmallRowRangeColumn2(RangeRequest rangeRequest, int sizeLimit) { ColumnSelection colSelection = ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d"))); @@ -249,7 +250,7 @@ public LinkedHashMap getSmallRowRangeColumn2(RangeRequest rangeR Preconditions.checkArgument(rangeRequest.getColumnNames().size() <= 1, "Must not request columns other than Column2."); - LinkedHashMap resultsMap = new LinkedHashMap<>(); + LinkedHashMap resultsMap = new LinkedHashMap<>(); BatchingVisitableView.of(t.getRange(tableRef, rangeRequest)) .batchAccept(sizeLimit, batch -> { batch.forEach(entry -> { @@ -293,7 +294,7 @@ public void deleteColumn2(String component1) { /** * Takes the row-keys and a value to be inserted at column Column1. */ - public void putColumn1(String component1, Long column1) { + public void putColumn1(String component1, long column1) { SchemaApiTestTable.SchemaApiTestRow row = SchemaApiTestTable.SchemaApiTestRow.of(component1); t.put(tableRef, ColumnValues.toCellValues(ImmutableMultimap.of(row, SchemaApiTestTable.Column1.of(column1)))); } @@ -314,7 +315,7 @@ public void updateColumn1(String component1, Function processor) { /** * Takes the row-keys and a value to be inserted at column Column2. */ - public void putColumn2(String component1, String column2) { + public void putColumn2(String component1, StringValue column2) { SchemaApiTestTable.SchemaApiTestRow row = SchemaApiTestTable.SchemaApiTestRow.of(component1); t.put(tableRef, ColumnValues.toCellValues(ImmutableMultimap.of(row, SchemaApiTestTable.Column2.of(column2)))); } @@ -323,10 +324,10 @@ public void putColumn2(String component1, String column2) { * Takes a function that would update the value at column Column2, for the specified row * components. No effect if there is no value at that column. Doesn't do an additional * write if the new value is the same as the old one. */ - public void updateColumn2(String component1, Function processor) { - Optional result = getColumn2(component1); + public void updateColumn2(String component1, Function processor) { + Optional result = getColumn2(component1); if (result.isPresent()) { - String newValue = processor.apply(result.get()); + StringValue newValue = processor.apply(result.get()); if (Objects.equals(newValue, result.get()) == false) { putColumn2(component1, processor.apply(result.get())); } diff --git a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValue.java b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValue.java new file mode 100644 index 00000000000..bf89a4bf06c --- /dev/null +++ b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValue.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017 Palantir Technologies, Inc. All rights reserved. + * + * Licensed under the BSD-3 License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.atlasdb.table.description.test; + +import org.immutables.value.Value; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@Value.Immutable +@JsonSerialize(as=ImmutableStringValue.class) +@JsonDeserialize(as=ImmutableStringValue.class) +public interface StringValue { + + String value(); + + static StringValue of(String value) { + return ImmutableStringValue.builder().value(value).build(); + } + +} diff --git a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValuePersister.java b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValuePersister.java new file mode 100644 index 00000000000..bfd38c2df40 --- /dev/null +++ b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/test/StringValuePersister.java @@ -0,0 +1,29 @@ +/* + * Copyright 2017 Palantir Technologies, Inc. All rights reserved. + * + * Licensed under the BSD-3 License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.atlasdb.table.description.test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.palantir.atlasdb.persister.JacksonPersister; + +public class StringValuePersister extends JacksonPersister { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + public StringValuePersister() { + super(StringValue.class, MAPPER); + } +} diff --git a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ColumnValueDescription.java b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ColumnValueDescription.java index 7ceb6faca89..bd084469bf3 100644 --- a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ColumnValueDescription.java +++ b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ColumnValueDescription.java @@ -199,6 +199,27 @@ public String getJavaObjectTypeName() { return type.getJavaObjectClassName(); } + public Class getJavaTypeClass() { + if (format == Format.PERSISTER) { + return getPersister().getPersistingClassType(); + } + if (canonicalClassName != null) { + try { + return Class.forName(canonicalClassName); + } catch (ClassNotFoundException ex) { + throw new RuntimeException(ex); + } + } + return type.getJavaClass(); + } + + public Class getJavaObjectTypeClass() { + if (format == Format.PERSISTER || canonicalClassName != null) { + return getJavaTypeClass(); + } + return type.getJavaObjectClass(); + } + public Persister getPersister() { Preconditions.checkArgument(Format.PERSISTER == format); @SuppressWarnings("unchecked") @@ -274,7 +295,7 @@ public Class getImportClass() { public Class getImportClass(ClassLoader classLoader) { if (className == null) { - return type.getTypeClass(); + return type.getJavaClass(); } try { return Class.forName(className, true, classLoader); diff --git a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/TableDefinition.java b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/TableDefinition.java index 7b87969d03f..b12eae2fded 100644 --- a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/TableDefinition.java +++ b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/TableDefinition.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Set; +import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -339,6 +340,12 @@ public boolean hasV2TableEnabled() { return this.v2TableEnabled; } + /** + * Enables generates of a separate set of "v2" tables, with simplified APIs for reading and writing data. + * + * This is a beta feature. API stability is not guaranteed, and the risk of defects is higher. + */ + @Beta public void enableV2Table() { this.v2TableEnabled = true; } diff --git a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ValueType.java b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ValueType.java index 86da422169e..23840ec15a5 100644 --- a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ValueType.java +++ b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/ValueType.java @@ -68,13 +68,13 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "long"; + public Class getJavaClass() { + return long.class; } @Override - public String getJavaObjectClassName() { - return "Long"; + public Class getJavaObjectClass() { + return Long.class; } @Override @@ -109,10 +109,6 @@ public String getPersistCode(String variableName) { return "EncodingUtils.encodeUnsignedVarLong(" + variableName + ")"; } - @Override - public Class getTypeClass() { - return Long.class; - } }, /** * This value type supports range scans. Neighboring number will be written next to each other. @@ -153,13 +149,13 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "long"; + public Class getJavaClass() { + return long.class; } @Override - public String getJavaObjectClassName() { - return "Long"; + public Class getJavaObjectClass() { + return Long.class; } @Override @@ -194,10 +190,6 @@ public String getPersistCode(String variableName) { return "EncodingUtils.encodeSignedVarLong(" + variableName + ")"; } - @Override - public Class getTypeClass() { - return Long.class; - } }, /** * This value type supports range scans. Sequential numbers will be written next to each other. @@ -237,13 +229,13 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "long"; + public Class getJavaClass() { + return long.class; } @Override - public String getJavaObjectClassName() { - return "Long"; + public Class getJavaObjectClass() { + return Long.class; } @Override @@ -278,10 +270,6 @@ public String getPersistCode(String variableName) { return "PtBytes.toBytes(Long.MIN_VALUE ^ " + variableName + ")"; } - @Override - public Class getTypeClass() { - return Long.class; - } }, /** * This value type does NOT support range scans. This encoding is {@link PtBytes#toBytes(long)} but with @@ -322,13 +310,13 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "long"; + public Class getJavaClass() { + return long.class; } @Override - public String getJavaObjectClassName() { - return "Long"; + public Class getJavaObjectClass() { + return Long.class; } @Override @@ -367,10 +355,7 @@ public String getPersistCode(String variableName) { public boolean supportsRangeScans() { return false; } - @Override - public Class getTypeClass() { - return Long.class; - } + }, /** * This value type supports range scans. Sequential numbers will be written next to each other. @@ -413,8 +398,8 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "Sha256Hash"; + public Class getJavaClass() { + return Sha256Hash.class; } @Override @@ -449,10 +434,6 @@ public String getHydrateSizeCode(String input) { return "32"; } - @Override - public Class getTypeClass() { - return Sha256Hash.class; - } }, /** * This value type DOES NOT support range scans. @@ -489,8 +470,8 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "String"; + public Class getJavaClass() { + return String.class; } @Override @@ -530,10 +511,6 @@ public String getPersistCode(String variableName) { return "EncodingUtils.encodeVarString(" + variableName + ")"; } - @Override - public Class getTypeClass() { - return String.class; - } }, STRING { @Override @@ -566,8 +543,8 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "String"; + public Class getJavaClass() { + return String.class; } @Override @@ -605,10 +582,6 @@ public String getPersistCode(String variableName) { return "PtBytes.toBytes(" + variableName + ")"; } - @Override - public Class getTypeClass() { - return String.class; - } }, BLOB { @Override @@ -639,8 +612,8 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "byte[]"; + public Class getJavaClass() { + return byte[].class; } @Override @@ -678,10 +651,6 @@ public String getHydrateSizeCode(String variableName) { return "0"; } - @Override - public Class getTypeClass() { - return byte[].class; - } }, /** * This value type DOES NOT support range scans. @@ -715,8 +684,8 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "byte[]"; + public Class getJavaClass() { + return byte[].class; } @Override @@ -756,10 +725,6 @@ public String getHydrateSizeCode(String variableName) { return "EncodingUtils.sizeOfSizedBytes(" + variableName + ")"; } - @Override - public Class getTypeClass() { - return byte[].class; - } }, NULLABLE_FIXED_LONG { @Override @@ -795,8 +760,8 @@ public byte[] convertFromJson(String jsonValue) { } @Override - public String getJavaClassName() { - return "Long"; + public Class getJavaClass() { + return Long.class; } @Override @@ -837,10 +802,6 @@ public String getPersistCode(String variableName) { return String.format("EncodingUtils.encodeNullableFixedLong(%s)", variableName); } - @Override - public Class getTypeClass() { - return Long.class; - } }, UUID { @Override @@ -882,6 +843,11 @@ public int sizeOf(Object value) { return 16; } + @Override + public Class getJavaClass() { + return java.util.UUID.class; + } + @Override public String getPersistCode(String variableName) { return String.format("EncodingUtils.encodeUUID(%s)", variableName); @@ -902,16 +868,6 @@ public String getHydrateSizeCode(String variableName) { return "16"; } - @Override - public String getJavaClassName() { - return UUID.class.getName(); - } - - @Override - public Class getTypeClass() { - return UUID.class; - } - } ; @@ -935,9 +891,15 @@ public boolean supportsRangeScans() { return true; } - public abstract String getJavaClassName(); + public abstract Class getJavaClass(); + public Class getJavaObjectClass() { + return getJavaClass(); + } + public String getJavaClassName() { + return getJavaClass().getSimpleName(); + } public String getJavaObjectClassName() { - return getJavaClassName(); + return getJavaObjectClass().getSimpleName(); } public abstract String getPersistCode(String variableName); public abstract String getHydrateCode(String inputName, String indexName); @@ -957,5 +919,4 @@ public static ValueType hydrateFromProto(TableMetadataPersistence.ValueType mess return valueOf(message.name()); } - public abstract Class getTypeClass(); } diff --git a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/Renderers.java b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/Renderers.java index fdabc3e5d44..a31f47b0da7 100644 --- a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/Renderers.java +++ b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/Renderers.java @@ -89,8 +89,12 @@ static String getIndexTableName(IndexMetadata index) { } } - public static Class getColumnTypeClass(NamedColumnDescription col) { - return col.getValue().getValueType().getTypeClass(); + public static Class getColumnClassForGenericTypeParameter(NamedColumnDescription col) { + return col.getValue().getJavaObjectTypeClass(); + } + + public static Class getColumnClass(NamedColumnDescription col) { + return col.getValue().getJavaTypeClass(); } public static MethodSpec.Builder addParametersFromRowComponents( @@ -98,7 +102,7 @@ public static MethodSpec.Builder addParametersFromRowComponents( TableMetadata tableMetadata) { for (NameComponentDescription rowPart : getRowComponents(tableMetadata)) { methodFactory.addParameter( - rowPart.getType().getTypeClass(), + rowPart.getType().getJavaClass(), rowPart.getComponentName()); } return methodFactory; diff --git a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/TableClassRendererV2.java b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/TableClassRendererV2.java index 2b49d12686e..def367f96e2 100644 --- a/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/TableClassRendererV2.java +++ b/atlasdb-client/src/main/java/com/palantir/atlasdb/table/description/render/TableClassRendererV2.java @@ -21,7 +21,8 @@ import static com.palantir.atlasdb.table.description.render.Renderers.CamelCase; import static com.palantir.atlasdb.table.description.render.Renderers.addParametersFromRowComponents; import static com.palantir.atlasdb.table.description.render.Renderers.getArgumentsFromRowComponents; -import static com.palantir.atlasdb.table.description.render.Renderers.getColumnTypeClass; +import static com.palantir.atlasdb.table.description.render.Renderers.getColumnClass; +import static com.palantir.atlasdb.table.description.render.Renderers.getColumnClassForGenericTypeParameter; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -260,7 +261,7 @@ private MethodSpec renderNamedGetColumn(NamedColumnDescription col) { getterBuilder.returns(ParameterizedTypeName.get( ClassName.get(Optional.class), - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T row = $T.of($L)", rowType, rowType, getArgumentsFromRowComponents(tableMetadata)) .addStatement("byte[] bytes = row.persistToBytes()") @@ -295,13 +296,13 @@ private MethodSpec renderNamedGetSeveralRows(NamedColumnDescription col) { .addParameter( ParameterizedTypeName.get( ClassName.get(Iterable.class), - ClassName.get(rowComponent.getType().getTypeClass())), + ClassName.get(rowComponent.getType().getJavaClass())), "rowKeys"); getterBuilder.returns(ParameterizedTypeName.get( ClassName.get(Map.class), - ClassName.get(rowComponent.getType().getTypeClass()), - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(rowComponent.getType().getJavaClass()), + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T colSelection = \n " @@ -343,7 +344,7 @@ private MethodSpec renderNamedGetSeveralRowObjects(NamedColumnDescription col) { getterBuilder.returns(ParameterizedTypeName.get( ClassName.get(Map.class), rowType, - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T colSelection = \n " @@ -379,8 +380,8 @@ private MethodSpec renderNamedGetRangeColumn(NamedColumnDescription col) { .addParameter(RangeRequest.class, "rangeRequest") .returns(ParameterizedTypeName.get( ClassName.get(LinkedHashMap.class), - ClassName.get(rowComponent.getType().getTypeClass()), - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(rowComponent.getType().getJavaClass()), + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T colSelection =\n" @@ -392,8 +393,8 @@ private MethodSpec renderNamedGetRangeColumn(NamedColumnDescription col) { Preconditions.class, "Must not request columns other than " + VarName(col) + "." ) .addCode("\n") .addStatement("$T<$T, $T> resultsMap = new $T<>()", - LinkedHashMap.class, rowComponent.getType().getTypeClass(), - getColumnTypeClass(col), LinkedHashMap.class) + LinkedHashMap.class, rowComponent.getType().getJavaClass(), + getColumnClassForGenericTypeParameter(col), LinkedHashMap.class) .addStatement("$T.of(t.getRange(tableRef, rangeRequest))\n" + ".immutableCopy().forEach(entry -> {\n" + " $T resultEntry =\n " @@ -417,12 +418,12 @@ private MethodSpec renderNamedGetRangeStartEnd(NamedColumnDescription col) { + "(if that column exists for the row-key). As the $L values are all loaded in memory,\n" + "do not use for large amounts of data. The order of results is preserved in the map.", VarName(col), VarName(col)) - .addParameter(rowComponent.getType().getTypeClass(), "startInclusive") - .addParameter(rowComponent.getType().getTypeClass(), "endExclusive") + .addParameter(rowComponent.getType().getJavaClass(), "startInclusive") + .addParameter(rowComponent.getType().getJavaClass(), "endExclusive") .returns(ParameterizedTypeName.get( ClassName.get(LinkedHashMap.class), - ClassName.get(rowComponent.getType().getTypeClass()), - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(rowComponent.getType().getJavaClass()), + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T rangeRequest = $T.builder()\n" @@ -448,8 +449,8 @@ private MethodSpec renderNamedGetRangeColumnLimit(NamedColumnDescription col) { .addParameter(int.class, "sizeLimit") .returns(ParameterizedTypeName.get( ClassName.get(LinkedHashMap.class), - ClassName.get(rowComponent.getType().getTypeClass()), - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(rowComponent.getType().getJavaClass()), + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T colSelection =\n" @@ -462,8 +463,8 @@ private MethodSpec renderNamedGetRangeColumnLimit(NamedColumnDescription col) { Preconditions.class, "Must not request columns other than " + VarName(col) + "." ) .addCode("\n") .addStatement("$T<$T, $T> resultsMap = new $T<>()", - LinkedHashMap.class, rowComponent.getType().getTypeClass(), - getColumnTypeClass(col), LinkedHashMap.class) + LinkedHashMap.class, rowComponent.getType().getJavaClass(), + getColumnClassForGenericTypeParameter(col), LinkedHashMap.class) .addStatement("$T.of(t.getRange(tableRef, rangeRequest))\n" + ".batchAccept(sizeLimit, batch -> {\n" + " batch.forEach(entry -> {\n" @@ -491,7 +492,7 @@ private MethodSpec renderNamedGetRangeColumnRowObjects(NamedColumnDescription co .returns(ParameterizedTypeName.get( ClassName.get(LinkedHashMap.class), rowType, - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T colSelection =\n" @@ -503,7 +504,7 @@ private MethodSpec renderNamedGetRangeColumnRowObjects(NamedColumnDescription co Preconditions.class, "Must not request additional columns.") .addCode("\n") .addStatement("$T<$T, $T> resultsMap = new $T<>()", - LinkedHashMap.class, rowType, getColumnTypeClass(col), LinkedHashMap.class) + LinkedHashMap.class, rowType, getColumnClassForGenericTypeParameter(col), LinkedHashMap.class) .addStatement("$T.of(t.getRange(tableRef, rangeRequest))\n" + ".immutableCopy().forEach(entry -> {\n" + " $T resultEntry =\n " @@ -529,7 +530,7 @@ private MethodSpec renderNamedGetRangeColumnRowObjectsLimit(NamedColumnDescripti .returns(ParameterizedTypeName.get( ClassName.get(LinkedHashMap.class), rowType, - ClassName.get(getColumnTypeClass(col)))); + ClassName.get(getColumnClassForGenericTypeParameter(col)))); getterBuilder .addStatement("$T colSelection =\n" @@ -542,7 +543,7 @@ private MethodSpec renderNamedGetRangeColumnRowObjectsLimit(NamedColumnDescripti Preconditions.class, "Must not request columns other than " + VarName(col) + "." ) .addCode("\n") .addStatement("$T<$T, $T> resultsMap = new $T<>()", - LinkedHashMap.class, rowType, getColumnTypeClass(col), LinkedHashMap.class) + LinkedHashMap.class, rowType, getColumnClassForGenericTypeParameter(col), LinkedHashMap.class) .addStatement("$T.of(t.getRange(tableRef, rangeRequest))\n" + ".batchAccept(sizeLimit, batch -> {\n" + " batch.forEach(entry -> {\n" @@ -626,7 +627,7 @@ private MethodSpec renderNamedPutColumn(NamedColumnDescription col) { putColumnBuilder = addParametersFromRowComponents(putColumnBuilder, tableMetadata); TypeName columnValueType = tableType.nestedClass(VarName(col)); - putColumnBuilder.addParameter(getColumnTypeClass(col), col.getLongName()); + putColumnBuilder.addParameter(getColumnClass(col), col.getLongName()); putColumnBuilder .addStatement("$T row = $T.of($L)", rowType, rowType, getArgumentsFromRowComponents(tableMetadata)) .addStatement("t.put(tableRef, $T.toCellValues($T.of(row, $T.of($L))))", @@ -644,14 +645,14 @@ private MethodSpec renderNamedUpdateColumn(NamedColumnDescription col) { updateColumnIfExistsBuilder = addParametersFromRowComponents(updateColumnIfExistsBuilder, tableMetadata); updateColumnIfExistsBuilder.addParameter(ParameterizedTypeName.get( ClassName.get(Function.class), - ClassName.get(getColumnTypeClass(col)), - ClassName.get(getColumnTypeClass(col))), "processor"); + ClassName.get(getColumnClassForGenericTypeParameter(col)), + ClassName.get(getColumnClassForGenericTypeParameter(col))), "processor"); String args = getArgumentsFromRowComponents(tableMetadata); updateColumnIfExistsBuilder .addStatement("$T<$T> result = get$L($L)", - Optional.class, getColumnTypeClass(col), VarName(col), args) + Optional.class, getColumnClassForGenericTypeParameter(col), VarName(col), args) .beginControlFlow("if (result.isPresent())") - .addStatement("$T newValue = processor.apply(result.get())", getColumnTypeClass(col)) + .addStatement("$T newValue = processor.apply(result.get())", getColumnClassForGenericTypeParameter(col)) .beginControlFlow("if ($T.equals(newValue, result.get()) == false)", Objects.class) .addStatement("put$L($L, processor.apply(result.get()))", VarName(col), args) .endControlFlow() diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/AbstractSchemaApiTest.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/AbstractSchemaApiTest.java index 20f2e3d4214..db01969f051 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/AbstractSchemaApiTest.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/AbstractSchemaApiTest.java @@ -47,13 +47,16 @@ import com.palantir.atlasdb.keyvalue.api.RowResult; import com.palantir.atlasdb.keyvalue.api.TableReference; import com.palantir.atlasdb.ptobject.EncodingUtils; +import com.palantir.atlasdb.table.description.generated.SchemaApiTestTable; +import com.palantir.atlasdb.table.description.test.StringValue; +import com.palantir.atlasdb.table.description.test.StringValuePersister; import com.palantir.atlasdb.transaction.api.Transaction; import com.palantir.atlasdb.transaction.impl.AbstractTransaction; import com.palantir.common.base.BatchingVisitableFromIterable; public abstract class AbstractSchemaApiTest { private static final TableReference tableRef = - TableReference.create(Namespace.DEFAULT_NAMESPACE, "SchemaApiTest"); + TableReference.create(Namespace.DEFAULT_NAMESPACE, SchemaApiTestTable.getRawTableName()); protected static final String TEST_ROW_KEY = "testRowKey"; protected static final String TEST_ROW_KEY2 = "testRowKey2"; @@ -61,9 +64,11 @@ public abstract class AbstractSchemaApiTest { protected static final String RANGE_END_ROW_KEY = "testRowKeyEndRange"; protected static final long TEST_VALUE_LONG = 2L; protected static final long TEST_VALUE_LONG2 = 3L; - protected static final String TEST_VALUE_STRING = "value1"; - protected static final String TEST_VALUE_STRING2 = "value2"; - protected static final String TEST_VALUE_STRING3 = "value3"; + protected static final StringValue TEST_VALUE_STRING = StringValue.of("value1"); + protected static final StringValue TEST_VALUE_STRING2 = StringValue.of("value2"); + protected static final StringValue TEST_VALUE_STRING3 = StringValue.of("value3"); + + protected static final StringValuePersister STRING_VALUE_PERSISTER = new StringValuePersister(); protected static final String FIRST_COL_SHORT_NAME = "c"; protected static final String SECOND_COL_SHORT_NAME = "d"; @@ -76,8 +81,10 @@ public abstract class AbstractSchemaApiTest { protected abstract void putSingleRowFirstColumn(Transaction transaction, String roWKey, long value); protected abstract Long getSingleRowFirstColumn(Transaction transaction, String rowKey); protected abstract Map getMultipleRowsFirstColumn(Transaction transaction, List rowKey); - protected abstract Map getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey); - protected abstract Map getRangeSecondColumnOnlyFirstTwoResults(Transaction transaction, String testRowKey, + protected abstract Map getRangeSecondColumn(Transaction transaction, String startRowKey, + String endRowKey); + protected abstract Map getRangeSecondColumnOnlyFirstTwoResults(Transaction transaction, + String testRowKey, String rangeEndRowKey); protected abstract void deleteWholeRow(Transaction transaction, String rowKey); protected abstract void deleteFirstColumn(Transaction transaction, String rowKey); @@ -156,12 +163,12 @@ public void testRowRangeSecondColumn() { .build(); when(transaction.getRange(tableRef, expectedRange)).thenReturn( BatchingVisitableFromIterable.create(Arrays.asList( - RowResult.of(expectedCell, TEST_VALUE_STRING.getBytes()), - RowResult.of(anotherExpectedCell, TEST_VALUE_STRING2.getBytes()) + RowResult.of(expectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING)), + RowResult.of(anotherExpectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING2)) )) ); - Map result = getRangeSecondColumn(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY); + Map result = getRangeSecondColumn(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY); assertThat(result) .isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_STRING, TEST_ROW_KEY2, TEST_VALUE_STRING2)); @@ -182,13 +189,14 @@ public void testRowRangeSecondColumnFirstTwoResults() { .build(); when(transaction.getRange(tableRef, expectedRange)).thenReturn( BatchingVisitableFromIterable.create(Arrays.asList( - RowResult.of(expectedCell, TEST_VALUE_STRING.getBytes()), - RowResult.of(anotherExpectedCell, TEST_VALUE_STRING2.getBytes()), - RowResult.of(cellToBeDroppedFromResults, TEST_VALUE_STRING3.getBytes()) + RowResult.of(expectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING)), + RowResult.of(anotherExpectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING2)), + RowResult.of(cellToBeDroppedFromResults, + STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING3)) )) ); - Map result = + Map result = getRangeSecondColumnOnlyFirstTwoResults(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY); assertThat(result) diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java index 171cfeddc91..931c9cd6297 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java @@ -19,6 +19,7 @@ import com.palantir.atlasdb.keyvalue.api.Namespace; import com.palantir.atlasdb.schema.AtlasSchema; +import com.palantir.atlasdb.table.description.test.StringValuePersister; /** * Schema used to test for Table API correctness and for accidental TableRenderer changes. @@ -37,14 +38,12 @@ private static Schema generateSchema() { schema.addTableDefinition("SchemaApiTest", new TableDefinition() { { - javaTableName("SchemaApiTest"); - rowName(); rowComponent("component1", ValueType.STRING); columns(); column("column1", "c", ValueType.VAR_LONG); - column("column2", "d", ValueType.STRING); + column("column2", "d", StringValuePersister.class); enableV2Table(); rangeScanAllowed(); @@ -53,8 +52,6 @@ private static Schema generateSchema() { schema.addTableDefinition("HashComponentsTest", new TableDefinition() { { - javaTableName("HashComponentsTest"); - rowName(); hashFirstNRowComponents(2); rowComponent("component1", ValueType.VAR_LONG); diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestImpl.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestImpl.java index 4602be5e057..934a0be7af5 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestImpl.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestImpl.java @@ -35,6 +35,7 @@ import com.palantir.atlasdb.table.description.generated.SchemaApiTestTable; import com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow; import com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult; +import com.palantir.atlasdb.table.description.test.StringValue; import com.palantir.atlasdb.transaction.api.Transaction; import com.palantir.common.base.BatchingVisitableView; import com.palantir.common.base.BatchingVisitables; @@ -79,7 +80,7 @@ protected Map getMultipleRowsFirstColumn(Transaction transaction, } @Override - protected Map getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) { + protected Map getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) { SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction); ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection( @@ -100,7 +101,7 @@ protected Map getRangeSecondColumn(Transaction transaction, Stri } @Override - protected Map getRangeSecondColumnOnlyFirstTwoResults( + protected Map getRangeSecondColumnOnlyFirstTwoResults( Transaction transaction, String startRowKey, String endRowKey) { SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction); diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java index 223b1293d74..3695451a8b8 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java @@ -49,6 +49,7 @@ import com.palantir.atlasdb.table.description.generated.ApiTestTableFactory; import com.palantir.atlasdb.table.description.generated.SchemaApiTestTable; import com.palantir.atlasdb.table.description.generated.SchemaApiTestV2Table; +import com.palantir.atlasdb.table.description.test.StringValue; import com.palantir.atlasdb.transaction.api.Transaction; import com.palantir.atlasdb.transaction.impl.AbstractTransaction; @@ -76,13 +77,13 @@ protected Map getMultipleRowsFirstColumn(Transaction transaction, } @Override - protected Map getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) { + protected Map getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) { SchemaApiTestV2Table table = tableFactory.getSchemaApiTestV2Table(transaction); return table.getSmallRowRangeColumn2(startRowKey, endRowKey); } @Override - protected Map getRangeSecondColumnOnlyFirstTwoResults( + protected Map getRangeSecondColumnOnlyFirstTwoResults( Transaction transaction, String startRowKey, String endRowKey) { SchemaApiTestV2Table table = tableFactory.getSchemaApiTestV2Table(transaction); diff --git a/docs/source/release_notes/release-notes.rst b/docs/source/release_notes/release-notes.rst index fa416534667..3197a532cc1 100644 --- a/docs/source/release_notes/release-notes.rst +++ b/docs/source/release_notes/release-notes.rst @@ -73,6 +73,9 @@ develop Previously, the table reference was omitted, such that one might receive lines of the form ``Call to KVS.getRange on table RangeRequest{reverse=false} with range 1504 took {} ms.``. (`Pull Request `__) + * - |fixed| + - V2 generated tables now support using ``Persistable``s as column values. Note that this is still a beta feature, and API stability is not guaranteed. + (`Pull Request `__) .. <<<<------------------------------------------------------------------------------------------------------------->>>> @@ -109,7 +112,6 @@ v0.61.0 Previously, we would log a ``SafeArg`` for these batches that had no content. (`Pull Request `__) - .. <<<<------------------------------------------------------------------------------------------------------------->>>> ======= From 9033ef83ec91e9821fed2a2a6aed5623fac8d731 Mon Sep 17 00:00:00 2001 From: Nathan Ziebart Date: Fri, 20 Oct 2017 12:56:30 +0100 Subject: [PATCH 2/7] fix tests --- .../com/palantir/atlasdb/table/description/ApiTestSchema.java | 4 ++++ .../atlasdb/table/description/SchemaApiTestV2Impl.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java index 931c9cd6297..da674cd5f65 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/ApiTestSchema.java @@ -38,6 +38,8 @@ private static Schema generateSchema() { schema.addTableDefinition("SchemaApiTest", new TableDefinition() { { + javaTableName("SchemaApiTest"); + rowName(); rowComponent("component1", ValueType.STRING); @@ -52,6 +54,8 @@ private static Schema generateSchema() { schema.addTableDefinition("HashComponentsTest", new TableDefinition() { { + javaTableName("HashComponentsTest"); + rowName(); hashFirstNRowComponents(2); rowComponent("component1", ValueType.VAR_LONG); diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java index 3695451a8b8..025a751280f 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaApiTestV2Impl.java @@ -32,6 +32,7 @@ package com.palantir.atlasdb.table.description; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -126,6 +127,6 @@ public void testUpdateEntryIfEntryDoesNotExist() { table.updateColumn1(TEST_ROW_KEY, entry -> entry + 1); - verify(table, never()).putColumn1(any(), any()); + verify(table, never()).putColumn1(any(), anyLong()); } } From b814e30fd87ea6dd1d7e4cb6bb9476b446617f25 Mon Sep 17 00:00:00 2001 From: Samuel Souza Date: Tue, 24 Oct 2017 11:27:59 +0100 Subject: [PATCH 3/7] Fix release notes --- docs/source/release_notes/release-notes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/release_notes/release-notes.rst b/docs/source/release_notes/release-notes.rst index 3197a532cc1..39c1bbde0e0 100644 --- a/docs/source/release_notes/release-notes.rst +++ b/docs/source/release_notes/release-notes.rst @@ -74,7 +74,7 @@ develop (`Pull Request `__) * - |fixed| - - V2 generated tables now support using ``Persistable``s as column values. Note that this is still a beta feature, and API stability is not guaranteed. + - V2 generated tables now support using ``Persistable`` as column values. Note that this is still a beta feature, and API stability is not guaranteed. (`Pull Request `__) .. <<<<------------------------------------------------------------------------------------------------------------->>>> From 13ca3ac9b0236cee8d58832797ce1c31886e872f Mon Sep 17 00:00:00 2001 From: Samuel Souza Date: Tue, 24 Oct 2017 11:31:43 +0100 Subject: [PATCH 4/7] Fix release notes version --- docs/source/release_notes/release-notes.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/source/release_notes/release-notes.rst b/docs/source/release_notes/release-notes.rst index 4a9efba1c8a..78bc0f7fda2 100644 --- a/docs/source/release_notes/release-notes.rst +++ b/docs/source/release_notes/release-notes.rst @@ -94,6 +94,14 @@ develop This will provide more accurate metrics for when sweep is doing something. Sweeping run through the sweep endpoint will now also contribute to these metrics, before it didn't update any metrics which again distorted the view of what work sweep was doing on the DB. (`Pull Request `__) + * - |improved| |devbreak| + - Size of the transaction cache is now configurable. It is not anticipated end users will need to touch this; + it is more likely that this will be configured via per-service overrides for the services for whom the + current cache size is inadequate. + This is a small API change for users manually constructing a TransactionManager, which now requires a + transaction cache size parameter. Please add it from the AtlasDbConfig, or instead of manually creating + a TransactionManager, utilize the helpers in TransactionManagers to have this done for you. + (`Pull Request `__) .. <<<<------------------------------------------------------------------------------------------------------------->>>> @@ -115,15 +123,6 @@ v0.61.1 cause Cassandra to OOM if the values are large enough. (`Pull Request `__) - * - |improved| |devbreak| - - Size of the transaction cache is now configurable. It is not anticipated end users will need to touch this; - it is more likely that this will be configured via per-service overrides for the services for whom the - current cache size is inadequate. - This is a small API change for users manually constructing a TransactionManager, which now requires a - transaction cache size parameter. Please add it from the AtlasDbConfig, or instead of manually creating - a TransactionManager, utilize the helpers in TransactionManagers to have this done for you. - (`Pull Request `__) - .. <<<<------------------------------------------------------------------------------------------------------------->>>> ======= From f7425739f39dbfe4b3db133af53b25ba53152e4e Mon Sep 17 00:00:00 2001 From: Samuel Souza Date: Tue, 24 Oct 2017 13:51:31 +0100 Subject: [PATCH 5/7] Update hash --- .../table/description/generated/SchemaApiTestTable.java | 2 +- .../com/palantir/atlasdb/table/description/SchemaTest.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java index 071254ec9ae..1d32179dd1f 100644 --- a/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java +++ b/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestTable.java @@ -875,5 +875,5 @@ public List findConstraintFailuresNoRead(Map writes, * {@link UnsignedBytes} * {@link ValueType} */ - static String __CLASS_HASH = "fWhFhDMIHuO9N51DDthfNA=="; + static String __CLASS_HASH = "EzXb+gYbz78sOCBS83b8DA=="; } diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaTest.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaTest.java index 9c4f9ea6776..3ce015f9115 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaTest.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/table/description/SchemaTest.java @@ -43,7 +43,6 @@ import com.palantir.atlasdb.keyvalue.api.TableReference; public class SchemaTest { - @Rule public TemporaryFolder testFolder = new TemporaryFolder(); @@ -51,6 +50,7 @@ public class SchemaTest { private static final String TEST_TABLE_NAME = "TestTable"; private static final String TEST_PATH = TEST_PACKAGE + "/" + TEST_TABLE_NAME + "Table.java"; private static final TableReference TABLE_REF = TableReference.createWithEmptyNamespace(TEST_TABLE_NAME); + private static final String EXPECTED_FILES_FOLDER_PATH = "src/integrationInput/java"; @Test public void testRendersGuavaOptionalsByDefault() throws IOException { @@ -139,6 +139,7 @@ public void testLongTableNameLengthFailsNamespace() throws IOException { @Test // If you are intentionally making Table API changes, please manually regenerate the ApiTestSchema + // and copy the new files to the ${EXPECTED_FILES_FOLDER_PATH} folder. public void checkAgainstAccidentalTableAPIChanges() throws IOException { // TODO (amarzoca): Add tests for schemas that use more of the rendering features (Triggers, StreamStores, etc) Schema schema = ApiTestSchema.getSchema(); @@ -170,7 +171,7 @@ private void checkIfFilesAreTheSame(List generatedTestTables) { String generatedFilePath = String.format("com/palantir/atlasdb/table/description/generated/%s.java", tableName); - File expectedFile = new File("src/integrationInput/java", generatedFilePath); + File expectedFile = new File(EXPECTED_FILES_FOLDER_PATH, generatedFilePath); File actualFile = new File(testFolder.getRoot(), generatedFilePath); assertThat(actualFile).hasSameContentAs(expectedFile); }); From 8f80cfc07e9b8c66f50d3ff65e3612b1c510f4eb Mon Sep 17 00:00:00 2001 From: Samuel Souza Date: Thu, 26 Oct 2017 16:13:16 +0100 Subject: [PATCH 6/7] Fix release notes --- docs/source/release_notes/release-notes.rst | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/source/release_notes/release-notes.rst b/docs/source/release_notes/release-notes.rst index 588b48b381e..2f0f6b3c97e 100644 --- a/docs/source/release_notes/release-notes.rst +++ b/docs/source/release_notes/release-notes.rst @@ -115,19 +115,10 @@ develop This will provide more accurate metrics for when sweep is doing something. Sweeping run through the sweep endpoint will now also contribute to these metrics, before it didn't update any metrics which again distorted the view of what work sweep was doing on the DB. (`Pull Request `__) - * - |improved| |devbreak| - - Size of the transaction cache is now configurable. It is not anticipated end users will need to touch this; - it is more likely that this will be configured via per-service overrides for the services for whom the - current cache size is inadequate. - This is a small API change for users manually constructing a TransactionManager, which now requires a - transaction cache size parameter. Please add it from the AtlasDbConfig, or instead of manually creating - a TransactionManager, utilize the helpers in TransactionManagers to have this done for you. - (`Pull Request `__) - - * - |devbreak| - - Simplify and annotate the constructors for ``SerializableTransactionManager``. This should make the code of that class more maintainable. - If you used one of the deleted or deprecated constructors, use the static ``create`` method. - (`Pull Request `__) + * - |devbreak| + - Simplify and annotate the constructors for ``SerializableTransactionManager``. This should make the code of that class more maintainable. + If you used one of the deleted or deprecated constructors, use the static ``create`` method. + (`Pull Request `__) .. <<<<------------------------------------------------------------------------------------------------------------->>>> From 15c3d362ebaeb81e0711f14a38ac9734e3abd1d3 Mon Sep 17 00:00:00 2001 From: Samuel Souza Date: Thu, 26 Oct 2017 16:22:22 +0100 Subject: [PATCH 7/7] Readd release notes --- docs/source/release_notes/release-notes.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/source/release_notes/release-notes.rst b/docs/source/release_notes/release-notes.rst index 2f0f6b3c97e..50d254a5fd7 100644 --- a/docs/source/release_notes/release-notes.rst +++ b/docs/source/release_notes/release-notes.rst @@ -120,6 +120,15 @@ develop If you used one of the deleted or deprecated constructors, use the static ``create`` method. (`Pull Request `__) + * - |improved| |devbreak| + - Size of the transaction cache is now configurable. It is not anticipated end users will need to touch this; + it is more likely that this will be configured via per-service overrides for the services for whom the + current cache size is inadequate. + This is a small API change for users manually constructing a TransactionManager, which now requires a + transaction cache size parameter. Please add it from the AtlasDbConfig, or instead of manually creating + a TransactionManager, utilize the helpers in TransactionManagers to have this done for you. + (`Pull Request `__) + .. <<<<------------------------------------------------------------------------------------------------------------->>>> =======