use of com.helger.genericode.v10.Column in project beam by apache.
the class BigtableTableTestUtils method setFixedTimestamp.
// There is no possibility to insert a value with fixed timestamp so we have to replace it
// for the testing purpose.
static com.google.bigtable.v2.Row setFixedTimestamp(com.google.bigtable.v2.Row row) {
Family family = row.getFamilies(0);
List<Column> columnsReplaced = family.getColumnsList().stream().map(column -> {
Cell cell = column.getCells(0);
return column(column.getQualifier().toStringUtf8(), cell.getValue().toByteArray());
}).collect(toList());
Family familyReplaced = Family.newBuilder().setName(family.getName()).addAllColumns(columnsReplaced).build();
return com.google.bigtable.v2.Row.newBuilder().setKey(row.getKey()).addFamilies(familyReplaced).build();
}
use of com.helger.genericode.v10.Column in project beam by apache.
the class BigtableTableTestUtils method bigTableRow.
static com.google.bigtable.v2.Row bigTableRow() {
List<Column> columns = ImmutableList.of(column("boolColumn", booleanToByteArray(true)), column("doubleColumn", doubleToByteArray(5.5)), column("longColumn", Longs.toByteArray(10L)), column("stringColumn", "stringValue".getBytes(UTF_8)));
Family family = Family.newBuilder().setName("familyTest").addAllColumns(columns).build();
return com.google.bigtable.v2.Row.newBuilder().setKey(byteStringUtf8("key")).addFamilies(family).build();
}
use of com.helger.genericode.v10.Column in project jaxdb by jaxdb.
the class Generator method makeTable.
private String makeTable(final Table table, final Map<String, Table> tableNameToTable) throws GeneratorExecutionException {
final String tableName = table.getName$().text();
final Info info = new Info();
final Type[] types = getTypes(table, tableNameToTable, 0, info);
final int noColumnsLocal = table.getColumn() == null ? 0 : table.getColumn().size();
final int noColumnsTotal = types.length;
final String classSimpleName = Identifiers.toClassCase(tableName);
final String className = schemaClassName + "." + classSimpleName;
final String instanceName = Identifiers.toInstanceCase(tableName);
final StringBuilder out = new StringBuilder();
if (!table.getAbstract$().text()) {
out.append("\n private static final ").append(className).append(" $").append(instanceName).append(" = new ").append(className).append("(false, false);\n\n");
out.append(" public static ").append(className).append(' ').append(classSimpleName).append("() {\n");
out.append(" return $").append(instanceName).append(";\n");
out.append(" }\n");
}
final String ext = table.getExtends$() == null ? data.Table.class.getCanonicalName() + "<" + className + ">" : Identifiers.toClassCase(table.getExtends$().text());
final String abs = table.getAbstract$().text() ? " abstract" : "";
out.append(getDoc(table, 1, '\0', '\n'));
out.append("\n public").append(abs).append(" static class ").append(classSimpleName).append(" extends ").append(ext).append(" {\n");
if (table.getExtends$() == null) {
out.append(" private final ").append(Key.class.getName()).append('<').append(className).append("> _primaryKey$ = new ").append(Key.class.getName()).append("<>(this);\n\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" public final ").append(Key.class.getName()).append('<').append(className).append("> getKey() {\n");
out.append(" return _primaryKey$;\n");
out.append(" }\n\n");
}
if (!table.getAbstract$().text()) {
out.append(" private static final ").append(String.class.getName()).append("[] _columnName$ = {");
for (int i = 0; i < noColumnsTotal; ++i) // FIXME: Hacking this to record what is the index of each column
types[i].column.text(String.valueOf(i));
final List<$Column> sortedColumns = new ArrayList<>();
for (final Type type : types) sortedColumns.add(type.column);
sortedColumns.sort(namedComparator);
for (final $Column column : sortedColumns) out.append("\"").append(column.getName$().text()).append("\", ");
out.setCharAt(out.length() - 2, '}');
out.setCharAt(out.length() - 1, ';');
out.append("\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" ").append(String.class.getName()).append("[] _columnName$() {\n");
out.append(" return _columnName$;\n");
out.append(" }\n\n");
out.append(" private static final byte[] _columnIndex$ = {");
for (final $Column column : sortedColumns) out.append(column.text()).append(", ");
out.setCharAt(out.length() - 2, '}');
out.setCharAt(out.length() - 1, ';');
out.append('\n');
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" byte[] _columnIndex$() {\n");
out.append(" return _columnIndex$;\n");
out.append(" }\n\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" public ").append(String.class.getName()).append(" getName() {\n");
out.append(" return \"").append(tableName).append("\";\n");
out.append(" }\n\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" ").append(className).append(" newInstance() {\n");
out.append(" return new ").append(className).append("(true, true);\n");
out.append(" }\n\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" ").append(className).append(" immutable() {\n");
out.append(" return $").append(instanceName).append(";\n");
out.append(" }\n\n");
final StringBuilder init = new StringBuilder();
newColumnArray(init, noColumnsTotal).append(", ");
newColumnArray(init, info.totalPrimaryCount.count).append(", ");
newColumnArray(init, info.totalKeyForUpdateCount.count).append(", ");
newColumnArray(init, info.totalAutoCount.count);
out.append(" ").append(classSimpleName).append("(final boolean _mutable$, final boolean _wasSelected$) {\n");
out.append(" this(_mutable$, _wasSelected$, ").append(init).append(", null, false);\n");
out.append(" }\n\n");
out.append(" /** Creates a new {@link ").append(className).append("}. */\n");
out.append(" public ").append(classSimpleName).append("() {\n");
out.append(" this(null, false);\n");
out.append(" }\n\n");
// Constructor with primary key columns
if (info.totalPrimaryCount.count > 0) {
final StringBuilder set = new StringBuilder();
out.append(" /** Creates a new {@link ").append(className).append("} with the specified primary key. */\n");
out.append(" public ").append(classSimpleName).append("(");
final StringBuilder params = new StringBuilder();
for (final Type type : types) {
if (type.isPrimary) {
params.append(type.makeParam()).append(", ");
final String fieldName = Identifiers.toCamelCase(type.column.getName$().text());
set.append(" this.").append(fieldName).append(".set(").append(fieldName).append(");\n");
}
}
params.setLength(params.length() - 2);
out.append(params).append(") {\n");
out.append(" this();\n");
if (set.length() > 0) {
set.setLength(set.length() - 1);
out.append(set);
}
out.append("\n }\n\n");
}
// Copy constructor
out.append(" /** Creates a new {@link ").append(className).append("} as a copy of the specified {@link ").append(className).append("} instance. */\n");
out.append(" public ").append(classSimpleName).append("(final ").append(className).append(" copy) {\n");
out.append(" this(copy, true);\n");
out.append(" }\n\n");
out.append(" /** Creates a new {@link ").append(className).append("} as a copy of the specified {@link ").append(className).append("} instance. */\n");
out.append(" ").append(classSimpleName).append("(final ").append(className).append(" copy, final boolean wasSet) {\n");
out.append(" this(true, false, ").append(init).append(", copy, wasSet);\n");
out.append(" }\n\n");
}
out.append(" ").append(classSimpleName).append("(final boolean _mutable$, final boolean _wasSelected$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _column$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _primary$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _keyForUpdate$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _auto$, final ").append(className).append(" copy, final boolean wasSet) {\n");
out.append(" super(_mutable$, _wasSelected$, _column$, _primary$, _keyForUpdate$, _auto$");
if (table.getExtends$() != null)
out.append(", copy, wasSet");
out.append(");\n");
int primaryIndex = info.totalPrimaryCount.offset;
int keyForUpdateIndex = info.totalKeyForUpdateCount.offset;
int autoIndex = info.totalAutoCount.offset;
for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
if (i > s)
out.append('\n');
final Type type = types[i];
out.append(" _column$[").append(i).append("] = ");
if (type.isPrimary)
out.append("_primary$[").append(primaryIndex++).append("] = ");
if (type.keyForUpdate)
out.append("_keyForUpdate$[").append(keyForUpdateIndex++).append("] = ");
if (org.jaxdb.ddlx.Generator.isAuto(type.column))
out.append("_auto$[").append(autoIndex++).append("] = ");
type.assignColumn(out);
}
out.append('\n');
out.append(" if (copy != null) {\n");
for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
if (i > s)
out.append('\n');
final Type type = types[i];
final String fieldName = Identifiers.toCamelCase(type.column.getName$().text());
out.append(" this.").append(fieldName).append(".copy(copy.").append(fieldName).append(", wasSet);");
}
out.append("\n }\n");
out.append(" }\n\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" void _merge$(final ").append(info.rootClassName).append(" table, final ").append(data.class.getName()).append(".Merge merge) {\n");
if (table.getExtends$() != null) {
out.append(" super._merge$(table, merge);\n");
out.append(" final ").append(className).append(" t = (").append(className).append(")table;\n");
} else {
out.append(" final ").append(className).append(" t = table;\n");
}
boolean hasColumnsToMerge = false;
for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
final Type type = types[i];
if (!type.isPrimary) {
if (hasColumnsToMerge)
out.append('\n');
hasColumnsToMerge = true;
final String fieldName = Identifiers.toCamelCase(type.column.getName$().text());
out.append(" if (t.").append(fieldName).append(".wasSet() || merge != null && ").append(fieldName).append(".generateOnUpdate != null)\n");
out.append(" ").append(fieldName).append(".copy(t.").append(fieldName).append(", true);\n");
}
}
out.append(" }\n");
for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) out.append(types[i].declareColumn());
out.append("\n\n");
if (table.getAbstract$().text()) {
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" public abstract ").append(className).append(" clone();\n\n");
} else {
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" public ").append(className).append(" clone() {\n");
out.append(" return new ").append(className).append("(this, false);\n");
out.append(" }\n\n");
}
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" public boolean equals(final ").append(Object.class.getName()).append(" obj) {\n");
out.append(" if (obj == this)\n");
out.append(" return true;\n\n");
out.append(" if (!(obj instanceof ").append(className).append("))\n");
out.append(" return false;\n\n");
if (table.getExtends$() != null) {
out.append(" if (!super.equals(obj))\n");
out.append(" return false;\n\n");
}
out.append(" final ").append(className).append(" that = (").append(className).append(")obj;");
for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
final Type type = types[i];
out.append("\n if (this.").append(type.getInstanceName()).append(".isNull() ? !that.").append(type.getInstanceName()).append(".isNull() : !this.").append(type.getInstanceName()).append(".get().equals(that.").append(type.getInstanceName()).append(".get()))");
out.append("\n return false;\n");
}
out.append("\n return true;");
out.append("\n }\n\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" public int hashCode() {\n");
if (table.getExtends$() != null)
out.append(" int hashCode = super.hashCode();");
else
out.append(" int hashCode = ").append(tableName.hashCode()).append(";");
for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
final Type type = types[i];
out.append("\n if (!this.").append(type.getInstanceName()).append(".isNull())");
out.append("\n hashCode = 31 * hashCode + this.").append(type.getInstanceName()).append(".get().hashCode();\n");
}
out.append("\n return hashCode;");
out.append("\n }\n\n");
out.append(" @").append(Override.class.getName()).append('\n');
out.append(" protected void toString(final boolean wasSetOnly, final ").append(StringBuilder.class.getName()).append(" s) {\n");
if (table.getExtends$() != null)
out.append(" super.toString(wasSetOnly, s);");
for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
final Type type = types[i];
final boolean ifClause = !type.isPrimary && !type.keyForUpdate;
if (ifClause)
out.append(" if (!wasSetOnly || this.").append(type.getInstanceName()).append(".wasSet)\n ");
out.append(" s.append(\",\\\"").append(type.column.getName$().text()).append("\\\":\").append(this.").append(type.getInstanceName()).append(".toJson());\n");
if (ifClause)
out.append('\n');
}
out.append(" if (s.length() > 0)\n");
out.append(" s.setCharAt(0, '{');\n");
out.append(" else\n");
out.append(" s.append('{');\n\n");
out.append(" s.append('}');");
out.append("\n }");
out.append("\n }");
return out.toString();
}
use of com.helger.genericode.v10.Column in project YCSB by brianfrankcooper.
the class GoogleBigtableClient method read.
@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
if (debug) {
System.out.println("Doing read from Bigtable columnfamily " + new String(columnFamilyBytes));
System.out.println("Doing read for key: " + key);
}
setTable(table);
RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
if (fields != null && fields.size() > 0) {
Builder filterChain = RowFilter.Chain.newBuilder();
filterChain.addFilters(filter);
filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
int count = 0;
// usually "field#" so pre-alloc
final StringBuilder regex = new StringBuilder(fields.size() * 6);
for (final String field : fields) {
if (count++ > 0) {
regex.append("|");
}
regex.append(field);
}
filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
}
final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRowKey(ByteStringer.wrap(key.getBytes()));
List<Row> rows;
try {
rows = client.readRowsAsync(rrr.build()).get();
if (rows == null || rows.isEmpty()) {
return Status.NOT_FOUND;
}
for (final Row row : rows) {
for (final Family family : row.getFamiliesList()) {
if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
for (final Column column : family.getColumnsList()) {
// we should only have a single cell per column
result.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
if (debug) {
System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
}
}
}
}
}
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Interrupted during get: " + e);
Thread.currentThread().interrupt();
return Status.ERROR;
} catch (ExecutionException e) {
System.err.println("Exception during get: " + e);
return Status.ERROR;
}
}
use of com.helger.genericode.v10.Column in project YCSB by brianfrankcooper.
the class GoogleBigtableClient method scan.
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
setTable(table);
RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
if (fields != null && fields.size() > 0) {
Builder filterChain = RowFilter.Chain.newBuilder();
filterChain.addFilters(filter);
filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
int count = 0;
// usually "field#" so pre-alloc
final StringBuilder regex = new StringBuilder(fields.size() * 6);
for (final String field : fields) {
if (count++ > 0) {
regex.append("|");
}
regex.append(field);
}
filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
}
final RowRange range = RowRange.newBuilder().setStartKey(ByteStringer.wrap(startkey.getBytes())).build();
final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRowRange(range);
List<Row> rows;
try {
rows = client.readRowsAsync(rrr.build()).get();
if (rows == null || rows.isEmpty()) {
return Status.NOT_FOUND;
}
int numResults = 0;
for (final Row row : rows) {
final HashMap<String, ByteIterator> rowResult = new HashMap<String, ByteIterator>(fields != null ? fields.size() : 10);
for (final Family family : row.getFamiliesList()) {
if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
for (final Column column : family.getColumnsList()) {
// we should only have a single cell per column
rowResult.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
if (debug) {
System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
}
}
}
}
result.add(rowResult);
numResults++;
if (numResults >= recordcount) {
// if hit recordcount, bail out
break;
}
}
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Interrupted during scan: " + e);
Thread.currentThread().interrupt();
return Status.ERROR;
} catch (ExecutionException e) {
System.err.println("Exception during scan: " + e);
return Status.ERROR;
}
}
Aggregations