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());
}
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();
}
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();
}
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(" */");
}
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("}");
}
Aggregations