Search in sources :

Example 11 with NameComponentDescription

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

the class TableMetadataSerializer method serialize.

private void serialize(JsonGenerator jgen, NameMetadataDescription rowMetadata) throws IOException {
    for (NameComponentDescription rowPart : rowMetadata.getRowParts()) {
        jgen.writeStartObject();
        jgen.writeObjectField("name", rowPart.getComponentName());
        jgen.writeObjectField("type", rowPart.getType());
        jgen.writeObjectField("order", rowPart.getOrder());
        jgen.writeEndObject();
    }
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription)

Example 12 with NameComponentDescription

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

the class TableClassRendererV2 method renderNamedGetRangeColumnLimit.

private MethodSpec renderNamedGetRangeColumnLimit(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 the first sizeLimit row keys in a rangeRequest to their value\n" + "at column $L (if that column exists). As the $L entries are all loaded in memory,\n" + "do not use for large values of sizeLimit. The order of results is preserved in the map.", VarName(col), VarName(col)).addParameter(RangeRequest.class, "rangeRequest").addParameter(int.class, "sizeLimit").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).batchHint(sizeLimit).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" + ".batchAccept(sizeLimit, batch -> {\n" + "     batch.forEach(entry -> {\n" + "         $T resultEntry =\n " + "             $T.of(entry);\n" + "         resultsMap.put(resultEntry.getRowName().get$L(), resultEntry.get$L());\n" + "     });\n" + "     return false; // stops the traversal after the first batch\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)

Example 13 with NameComponentDescription

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

the class TableClassRendererV2 method renderNamedGetSeveralRows.

private MethodSpec renderNamedGetSeveralRows(NamedColumnDescription col) {
    Preconditions.checkArgument(tableMetadata.getRowMetadata().getRowParts().size() == 1);
    NameComponentDescription rowComponent = tableMetadata.getRowMetadata().getRowParts().get(0);
    MethodSpec.Builder getterBuilder = MethodSpec.methodBuilder("get" + VarName(col)).addModifiers(Modifier.PUBLIC).addJavadoc("Returns a mapping from the specified row keys to their value at column $L.\n" + "As the $L values are all loaded in memory, do not use for large amounts of data.\n" + "If the column does not exist for a key, the entry will be omitted from the map.", VarName(col), VarName(col)).addParameter(ParameterizedTypeName.get(ClassName.get(Iterable.class), ClassName.get(rowComponent.getType().getJavaClass())), "rowKeys");
    getterBuilder.returns(ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(rowComponent.getType().getJavaClass()), TypeName.get(getColumnClassForGenericTypeParameter(col))));
    getterBuilder.addStatement("$T colSelection = \n " + "$T.create($T.of($T.toCachedBytes($S)))", ColumnSelection.class, ColumnSelection.class, ImmutableList.class, PtBytes.class, col.getShortName()).addStatement("$T<$T> rows = $T\n" + ".newArrayList(rowKeys)\n" + ".stream()\n" + ".map($T::of)\n" + ".collect($T.toList())", List.class, rowType, Lists.class, rowType, Collectors.class).addCode("\n").addStatement("$T<byte[], $T<byte[]>> results = " + "t.getRows(tableRef, $T.persistAll(rows), colSelection)", SortedMap.class, RowResult.class, Persistables.class).addStatement("return results\n" + ".values()\n" + ".stream()\n" + ".map(entry -> $T.of(entry))\n" + ".collect($T.toMap(\n" + "     entry -> entry.getRowName().get$L(), \n" + "     $T::get$L))", rowResultType, Collectors.class, CamelCase(rowComponent.getComponentName()), rowResultType, VarName(col));
    return getterBuilder.build();
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) Collectors(java.util.stream.Collectors) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) MethodSpec(com.squareup.javapoet.MethodSpec) Lists(com.google.common.collect.Lists) SortedMap(java.util.SortedMap) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Persistables(com.palantir.common.persist.Persistables)

Example 14 with NameComponentDescription

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

the class DynamicColumnValueRenderer method javaDoc.

private void javaDoc() {
    line("/**");
    line(" * <pre>");
    line(" * Column name description {", "");
    for (NameComponentDescription comp : col.getRowParts()) {
        boolean descending = comp.getOrder() == ValueByteOrder.DESCENDING;
        line(" *   {@literal ", descending ? "@Descending " : "", TypeName(comp), " ", varName(comp), "};");
    }
    line(" * }", "");
    line(" * Column value description {", "");
    line(" *   type: ", val.getJavaObjectTypeName(), ";");
    if (val.getProtoDescriptor() != null) {
        String protoDescription = val.getProtoDescriptor().toProto().toString();
        for (String line : protoDescription.split("\n")) {
            line(" *   ", line, "");
        }
    }
    line(" * }", "");
    line(" * </pre>");
    line(" */");
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription)

Example 15 with NameComponentDescription

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

the class RowOrDynamicColumnRenderer method renderComponentBytes.

private List<String> renderComponentBytes(List<NameComponentDescription> components) {
    List<String> vars = Lists.newArrayList();
    if (desc.numberOfComponentsHashed() > 0) {
        renderComputeFirstNComponentHash(desc.numberOfComponentsHashed());
        String var = NameMetadataDescription.HASH_ROW_COMPONENT_NAME + "Bytes";
        vars.add(var);
        line("byte[] ", var, " = ", ValueType.FIXED_LONG.getPersistCode(NameMetadataDescription.HASH_ROW_COMPONENT_NAME), ";");
    }
    for (NameComponentDescription comp : components) {
        String var = varName(comp) + "Bytes";
        vars.add(var);
        line("byte[] ", var, " = ", comp.getType().getPersistCode(varName(comp)), ";");
        if (comp.getOrder() == ValueByteOrder.DESCENDING) {
            line("EncodingUtils.flipAllBitsInPlace(", var, ");");
        }
    }
    return vars;
}
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