Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

support persistables in v2 tables #2495

Merged
merged 11 commits into from
Oct 27, 2017
3 changes: 3 additions & 0 deletions atlasdb-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ dependencies {
testCompile group: 'org.assertj', name: 'assertj-core'

integrationInputCompile project(":atlasdb-client")

integrationInputCompile group: 'org.immutables', name: 'value'

}
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,18 @@ public String toString() {
/**
* <pre>
* Column value description {
* type: String;
* type: com.palantir.atlasdb.table.description.test.StringValue;
* }
* </pre>
*/
public static final class Column2 implements SchemaApiTestNamedColumnValue<String> {
private final String value;
public static final class Column2 implements SchemaApiTestNamedColumnValue<com.palantir.atlasdb.table.description.test.StringValue> {
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;
}

Expand All @@ -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);
}

Expand All @@ -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)));
}
};

Expand Down Expand Up @@ -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;
Expand All @@ -422,10 +422,10 @@ public Long apply(SchemaApiTestRowResult rowResult) {
};
}

public static Function<SchemaApiTestRowResult, String> getColumn2Fun() {
return new Function<SchemaApiTestRowResult, String>() {
public static Function<SchemaApiTestRowResult, com.palantir.atlasdb.table.description.test.StringValue> getColumn2Fun() {
return new Function<SchemaApiTestRowResult, com.palantir.atlasdb.table.description.test.StringValue>() {
@Override
public String apply(SchemaApiTestRowResult rowResult) {
public com.palantir.atlasdb.table.description.test.StringValue apply(SchemaApiTestRowResult rowResult) {
return rowResult.getColumn2();
}
};
Expand Down Expand Up @@ -495,15 +495,15 @@ public Map<SchemaApiTestRow, Long> getColumn1s(Collection<SchemaApiTestRow> rows
return ret;
}

public Map<SchemaApiTestRow, String> getColumn2s(Collection<SchemaApiTestRow> rows) {
public Map<SchemaApiTestRow, com.palantir.atlasdb.table.description.test.StringValue> getColumn2s(Collection<SchemaApiTestRow> rows) {
Map<Cell, SchemaApiTestRow> cells = Maps.newHashMapWithExpectedSize(rows.size());
for (SchemaApiTestRow row : rows) {
cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("d")), row);
}
Map<Cell, byte[]> results = t.get(tableRef, cells.keySet());
Map<SchemaApiTestRow, String> ret = Maps.newHashMapWithExpectedSize(results.size());
Map<SchemaApiTestRow, com.palantir.atlasdb.table.description.test.StringValue> ret = Maps.newHashMapWithExpectedSize(results.size());
for (Entry<Cell, byte[]> 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;
Expand Down Expand Up @@ -533,25 +533,25 @@ public void putColumn1UnlessExists(Map<SchemaApiTestRow, Long> 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<SchemaApiTestRow, String> map) {
public void putColumn2(Map<SchemaApiTestRow, com.palantir.atlasdb.table.description.test.StringValue> map) {
Map<SchemaApiTestRow, SchemaApiTestNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size());
for (Entry<SchemaApiTestRow, String> e : map.entrySet()) {
for (Entry<SchemaApiTestRow, com.palantir.atlasdb.table.description.test.StringValue> 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<SchemaApiTestRow, String> map) {
public void putColumn2UnlessExists(Map<SchemaApiTestRow, com.palantir.atlasdb.table.description.test.StringValue> map) {
Map<SchemaApiTestRow, SchemaApiTestNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size());
for (Entry<SchemaApiTestRow, String> e : map.entrySet()) {
for (Entry<SchemaApiTestRow, com.palantir.atlasdb.table.description.test.StringValue> e : map.entrySet()) {
toPut.put(e.getKey(), Column2.of(e.getValue()));
}
putUnlessExists(Multimaps.forMap(toPut));
Expand Down Expand Up @@ -875,5 +875,5 @@ public List<String> findConstraintFailuresNoRead(Map<Cell, byte[]> writes,
* {@link UnsignedBytes}
* {@link ValueType}
*/
static String __CLASS_HASH = "r1lpoi0kpKMwjzfzxCBPow==";
static String __CLASS_HASH = "EzXb+gYbz78sOCBS83b8DA==";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,7 +167,7 @@ public LinkedHashMap<String, Long> getSmallRowRangeColumn1(RangeRequest rangeReq

/**
* Returns the value for column Column2 and specified row components. */
public Optional<String> getColumn2(String component1) {
public Optional<StringValue> getColumn2(String component1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not compile for me:

/Users/hsaraogi/code/atlasdb/atlasdb-client/src/integrationInput/java/com/palantir/atlasdb/table/description/generated/SchemaApiTestV2Table.java:330: error: cannot find symbol
            StringValue newValue = processor.apply(result.get());
            ^
  symbol:   class StringValue
  location: class SchemaApiTestV2Table
33 errors
:atlasdb-client:compileIntegrationInputJava FAILED

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, not compiling in circle either. let me fix it

SchemaApiTestTable.SchemaApiTestRow row = SchemaApiTestTable.SchemaApiTestRow.of(component1);
byte[] bytes = row.persistToBytes();
ColumnSelection colSelection =
Expand All @@ -184,7 +185,7 @@ public Optional<String> 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<String, String> getColumn2(Iterable<String> rowKeys) {
public Map<String, StringValue> getColumn2(Iterable<String> rowKeys) {
ColumnSelection colSelection =
ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
List<SchemaApiTestTable.SchemaApiTestRow> rows = Lists
Expand All @@ -207,14 +208,14 @@ public Map<String, String> getColumn2(Iterable<String> 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<String, String> getSmallRowRangeColumn2(RangeRequest rangeRequest) {
public LinkedHashMap<String, StringValue> 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<String, String> resultsMap = new LinkedHashMap<>();
LinkedHashMap<String, StringValue> resultsMap = new LinkedHashMap<>();
BatchingVisitableView.of(t.getRange(tableRef, rangeRequest))
.immutableCopy().forEach(entry -> {
SchemaApiTestTable.SchemaApiTestRowResult resultEntry =
Expand All @@ -228,7 +229,7 @@ public LinkedHashMap<String, String> 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<String, String> getSmallRowRangeColumn2(String startInclusive,
public LinkedHashMap<String, StringValue> getSmallRowRangeColumn2(String startInclusive,
String endExclusive) {
RangeRequest rangeRequest = RangeRequest.builder()
.startRowInclusive(SchemaApiTestTable.SchemaApiTestRow.of(startInclusive).persistToBytes())
Expand All @@ -241,15 +242,15 @@ public LinkedHashMap<String, String> 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<String, String> getSmallRowRangeColumn2(RangeRequest rangeRequest,
public LinkedHashMap<String, StringValue> getSmallRowRangeColumn2(RangeRequest rangeRequest,
int sizeLimit) {
ColumnSelection colSelection =
ColumnSelection.create(ImmutableList.of(PtBytes.toCachedBytes("d")));
rangeRequest = rangeRequest.getBuilder().retainColumns(colSelection).batchHint(sizeLimit).build();
Preconditions.checkArgument(rangeRequest.getColumnNames().size() <= 1,
"Must not request columns other than Column2.");

LinkedHashMap<String, String> resultsMap = new LinkedHashMap<>();
LinkedHashMap<String, StringValue> resultsMap = new LinkedHashMap<>();
BatchingVisitableView.of(t.getRange(tableRef, rangeRequest))
.batchAccept(sizeLimit, batch -> {
batch.forEach(entry -> {
Expand Down Expand Up @@ -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))));
}
Expand All @@ -314,7 +315,7 @@ public void updateColumn1(String component1, Function<Long, Long> 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))));
}
Expand All @@ -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<String, String> processor) {
Optional<String> result = getColumn2(component1);
public void updateColumn2(String component1, Function<StringValue, StringValue> processor) {
Optional<StringValue> 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()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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<StringValue> {

private static final ObjectMapper MAPPER = new ObjectMapper();

public StringValuePersister() {
super(StringValue.class, MAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Loading