Search in sources :

Example 1 with NameComponentDescription

use of com.palantir.atlasdb.table.description.NameComponentDescription in project atlasdb by palantir.

the class Renderers method getRowComponents.

public static List<NameComponentDescription> getRowComponents(TableMetadata tableMetadata) {
    NameMetadataDescription rowMetadata = tableMetadata.getRowMetadata();
    List<NameComponentDescription> rowParts = rowMetadata.getRowParts();
    return rowMetadata.numberOfComponentsHashed() == 0 ? rowParts : rowParts.subList(1, rowParts.size());
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription)

Example 2 with NameComponentDescription

use of com.palantir.atlasdb.table.description.NameComponentDescription in project atlasdb by palantir.

the class TableClassRendererV2 method renderNamedGetRangeStartEnd.

private MethodSpec renderNamedGetRangeStartEnd(NamedColumnDescription col) {
    Preconditions.checkArgument(tableMetadata.getRowMetadata().getRowParts().size() == 1);
    NameComponentDescription rowComponent = tableMetadata.getRowMetadata().getRowParts().get(0);
    MethodSpec.Builder getterBuilder = MethodSpec.methodBuilder("getSmallRowRange" + VarName(col)).addModifiers(Modifier.PUBLIC).addJavadoc("Returns a mapping from all the row keys in a range to their value at column $L\n" + "(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().getJavaClass(), "startInclusive").addParameter(rowComponent.getType().getJavaClass(), "endExclusive").returns(ParameterizedTypeName.get(ClassName.get(LinkedHashMap.class), ClassName.get(rowComponent.getType().getJavaClass()), ClassName.get(getColumnClassForGenericTypeParameter(col))));
    getterBuilder.addStatement("$T rangeRequest = $T.builder()\n" + ".startRowInclusive($T.of(startInclusive).persistToBytes())\n" + ".endRowExclusive($T.of(endExclusive).persistToBytes())\n" + ".build()", RangeRequest.class, RangeRequest.class, rowType, rowType).addStatement("return getSmallRowRange$L(rangeRequest)", VarName(col));
    return getterBuilder.build();
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) MethodSpec(com.squareup.javapoet.MethodSpec) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 3 with NameComponentDescription

use of com.palantir.atlasdb.table.description.NameComponentDescription in project atlasdb by palantir.

the class TableClassRendererV2 method renderNamedGetRangeColumn.

private MethodSpec renderNamedGetRangeColumn(NamedColumnDescription col) {
    Preconditions.checkArgument(tableMetadata.getRowMetadata().getRowParts().size() == 1);
    NameComponentDescription rowComponent = tableMetadata.getRowMetadata().getRowParts().get(0);
    MethodSpec.Builder getterBuilder = MethodSpec.methodBuilder("getSmallRowRange" + VarName(col)).addModifiers(Modifier.PUBLIC).addJavadoc("Returns a mapping from all the row keys in a rangeRequest to their value at column $L\n" + "(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(RangeRequest.class, "rangeRequest").returns(ParameterizedTypeName.get(ClassName.get(LinkedHashMap.class), ClassName.get(rowComponent.getType().getJavaClass()), ClassName.get(getColumnClassForGenericTypeParameter(col))));
    getterBuilder.addStatement("$T colSelection =\n" + "$T.create($T.of($T.toCachedBytes($L)))", ColumnSelection.class, ColumnSelection.class, ImmutableList.class, PtBytes.class, ColumnRenderers.short_name(col)).addStatement("rangeRequest = rangeRequest.getBuilder().retainColumns(colSelection).build()").addStatement("$T.checkArgument(rangeRequest.getColumnNames().size() <= 1,\n$S)", Preconditions.class, "Must not request columns other than " + VarName(col) + ".").addCode("\n").addStatement("$T<$T, $T> resultsMap = new $T<>()", LinkedHashMap.class, rowComponent.getType().getJavaClass(), getColumnClassForGenericTypeParameter(col), LinkedHashMap.class).addStatement("$T.of(t.getRange(tableRef, rangeRequest))\n" + ".immutableCopy().forEach(entry -> {\n" + "     $T resultEntry =\n " + "         $T.of(entry);\n" + "     resultsMap.put(resultEntry.getRowName().get$L(), resultEntry.get$L());\n" + "})", BatchingVisitableView.class, rowResultType, rowResultType, CamelCase(rowComponent.getComponentName()), VarName(col)).addStatement("return resultsMap");
    return getterBuilder.build();
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) MethodSpec(com.squareup.javapoet.MethodSpec) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 4 with NameComponentDescription

use of com.palantir.atlasdb.table.description.NameComponentDescription in project atlasdb by palantir.

the class RowOrDynamicColumnRenderer method javaDoc.

private void javaDoc() {
    line("/**");
    line(" * <pre>");
    line(" * ", Name, " {", "");
    for (NameComponentDescription comp : desc.getRowParts()) {
        boolean descending = comp.getOrder() == ValueByteOrder.DESCENDING;
        line(" *   {@literal ", descending ? "@Descending " : "", TypeName(comp), " ", varName(comp), "};");
    }
    line(" * }", "");
    line(" * </pre>");
    line(" */");
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription)

Example 5 with NameComponentDescription

use of com.palantir.atlasdb.table.description.NameComponentDescription in project atlasdb by palantir.

the class RowOrDynamicColumnRenderer method fromVarNameFun.

private void fromVarNameFun() {
    NameComponentDescription comp = Iterables.getOnlyElement(getRowPartsWithoutHash());
    line("public static Function<", TypeName(comp), ", ", Name, "> from", VarName(comp), "Fun() {");
    {
        line("return new Function<", TypeName(comp), ", ", Name, ">() {");
        {
            line("@Override");
            line("public ", Name, " apply(", TypeName(comp), " row) {");
            {
                line("return ", Name, ".of(row);");
            }
            line("}");
        }
        line("};");
    }
    line("}");
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription)

Aggregations

NameComponentDescription (com.palantir.atlasdb.table.description.NameComponentDescription)17 MethodSpec (com.squareup.javapoet.MethodSpec)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)2 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 ValueByteOrder (com.palantir.atlasdb.protos.generated.TableMetadataPersistence.ValueByteOrder)1 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)1 ValueType (com.palantir.atlasdb.table.description.ValueType)1 Persistables (com.palantir.common.persist.Persistables)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SortedMap (java.util.SortedMap)1 Collectors (java.util.stream.Collectors)1