Search in sources :

Example 16 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row in project molgenis-emx2 by molgenis.

the class TestCohortCatalogue method importStagingSchemas.

@Test
public void importStagingSchemas() {
    // import cdm that uses schemaRef to ontologies
    Schema cdmSchema = database.dropCreateSchema("Catalogue_cdm");
    MolgenisIO.fromDirectory(new File("../../data/datacatalogue/Catalogue_cdm").toPath(), cdmSchema, true);
    // export cdm and then import again, to validate it works
    List<Row> metadata = Emx2.toRowList(cdmSchema.getMetadata());
    Schema cdmSchema2 = database.dropCreateSchema("Catalogue_cdm2");
    cdmSchema2.migrate(Emx2.fromRowList(metadata));
}
Also used : Schema(org.molgenis.emx2.Schema) Row(org.molgenis.emx2.Row) File(java.io.File) Test(org.junit.Test)

Example 17 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row in project jaxdb by jaxdb.

the class Generator method getType.

private Type getType(final Table table, final $Column column) throws GeneratorExecutionException {
    final String columnName = column.getName$().text();
    boolean isKeyForUpdate = false;
    // FIXME: Make efficient
    if (table.getJsqlKeyForUpdate() != null)
        for (final xLygluGCXAA.$Named col : table.getJsqlKeyForUpdate().getColumn()) if (isKeyForUpdate = columnName.equals(col.getName$().text()))
            break;
    final Class<?> cls = column.getClass().getSuperclass();
    GenerateOn<?> generateOnInsert = null;
    GenerateOn<?> generateOnUpdate = null;
    final boolean isPrimary = ddlx.isPrimary(table, column);
    final Object[] commonParams = { THIS, MUTABLE, "\"" + column.getName$().text() + "\"", ddlx.isUnique(table, column), isPrimary, isNull(column) };
    if (column instanceof $Char) {
        final $Char type = ($Char) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Char.GenerateOnInsert$.UUID.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.UUID;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        return new Type(table, column, isPrimary, data.CHAR.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text(), isVarying(type.getVarying$()));
    }
    if (column instanceof $Clob) {
        final $Clob type = ($Clob) column;
        return new Type(table, column, isPrimary, data.CLOB.class, commonParams, null, generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text());
    }
    if (column instanceof $Binary) {
        final $Binary type = ($Binary) column;
        return new Type(table, column, isPrimary, data.BINARY.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text(), isVarying(type.getVarying$()));
    }
    if (column instanceof $Blob) {
        final $Blob type = ($Blob) column;
        return new Type(table, column, isPrimary, data.BLOB.class, commonParams, null, generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text());
    }
    if (column instanceof $Integer) {
        final $Integer integerColumn = ($Integer) column;
        if (integerColumn.getGenerateOnInsert$() != null) {
            if ($Integer.GenerateOnInsert$.AUTO_5FINCREMENT.text().equals(integerColumn.getGenerateOnInsert$().text())) {
                generateOnInsert = GenerateOn.AUTO_GENERATED;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integerColumn.getGenerateOnInsert$().text());
            }
        }
        if (column instanceof $Tinyint) {
            final $Tinyint integer = ($Tinyint) column;
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if ($Tinyint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (isPrimary)
                        throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.TINYINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Smallint) {
            final $Smallint integer = ($Smallint) column;
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if ($Smallint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (isPrimary)
                        throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.SMALLINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Int) {
            final $Int integer = ($Int) column;
            if (integer.getSqlxGenerateOnInsert$() != null) {
                if (generateOnInsert != null)
                    throw new GeneratorExecutionException("ddlx:generateOnInsert and sqlx:generateOnInsert are mutually exclusive");
                if ($Int.GenerateOnInsert$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnInsert = GenerateOn.EPOCH_MINUTES;
                } else if ($Int.GenerateOnInsert$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnInsert = GenerateOn.EPOCH_SECONDS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integer.getSqlxGenerateOnInsert$().text());
                }
            }
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                if ($Int.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else if ($Int.GenerateOnUpdate$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnUpdate = GenerateOn.EPOCH_MINUTES;
                } else if ($Int.GenerateOnUpdate$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnUpdate = GenerateOn.EPOCH_SECONDS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.INT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Bigint) {
            final $Bigint integer = ($Bigint) column;
            if (integer.getSqlxGenerateOnInsert$() != null) {
                if (generateOnInsert != null)
                    throw new GeneratorExecutionException("ddlx:generateOnInsert and sqlx:generateOnInsert are mutually exclusive");
                if ($Bigint.GenerateOnInsert$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnInsert = GenerateOn.EPOCH_MINUTES;
                } else if ($Bigint.GenerateOnInsert$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnInsert = GenerateOn.EPOCH_SECONDS;
                } else if ($Bigint.GenerateOnInsert$.EPOCH_5FMILLIS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 13)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 13 for EPOCH_MILLIS");
                    generateOnInsert = GenerateOn.EPOCH_MILLIS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integer.getSqlxGenerateOnInsert$().text());
                }
            }
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                if ($Bigint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnUpdate = GenerateOn.EPOCH_MINUTES;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnUpdate = GenerateOn.EPOCH_SECONDS;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FMILLIS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 13)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 13 for EPOCH_MILLIS");
                    generateOnUpdate = GenerateOn.EPOCH_MILLIS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.BIGINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
    }
    if (column instanceof $Float) {
        final $Float type = ($Float) column;
        final Class<? extends data.Column<?>> col = data.FLOAT.class;
        final Number min = type.getMin$() != null ? type.getMin$().text() : null;
        final Number max = type.getMax$() != null ? type.getMax$().text() : null;
        return new Type(table, column, isPrimary, col, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, min, max);
    }
    if (column instanceof $Double) {
        final $Double type = ($Double) column;
        final Class<? extends data.Column<?>> col = data.DOUBLE.class;
        final Number min = type.getMin$() != null ? type.getMin$().text() : null;
        final Number max = type.getMax$() != null ? type.getMax$().text() : null;
        return new Type(table, column, isPrimary, col, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, min, max);
    }
    if (column instanceof $Decimal) {
        final $Decimal type = ($Decimal) column;
        return new Type(table, column, isPrimary, data.DECIMAL.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getPrecision$() == null ? null : type.getPrecision$().text().intValue(), type.getScale$() == null ? null : type.getScale$().text().intValue(), type.getMin$() == null ? null : type.getMin$().text(), type.getMax$() == null ? null : type.getMax$().text());
    }
    if (column instanceof $Date) {
        final $Date type = ($Date) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Date.GenerateOnInsert$.TIMESTAMP.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        if (type.getSqlxGenerateOnUpdate$() != null) {
            if ($Date.GenerateOnUpdate$.TIMESTAMP.text().equals(type.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + type.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new Type(table, column, isPrimary, data.DATE.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    if (column instanceof $Time) {
        final $Time type = ($Time) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Time.GenerateOnInsert$.TIMESTAMP.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        if (type.getSqlxGenerateOnUpdate$() != null) {
            if ($Time.GenerateOnUpdate$.TIMESTAMP.text().equals(type.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + type.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new Type(table, column, isPrimary, data.TIME.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getPrecision$() == null ? null : type.getPrecision$().text());
    }
    if (column instanceof $Datetime) {
        final $Datetime type = ($Datetime) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Datetime.GenerateOnInsert$.TIMESTAMP.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        if (type.getSqlxGenerateOnUpdate$() != null) {
            if ($Datetime.GenerateOnUpdate$.TIMESTAMP.text().equals(type.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + type.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new Type(table, column, isPrimary, data.DATETIME.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getPrecision$() == null ? null : type.getPrecision$().text());
    }
    if (column instanceof $Boolean) {
        final $Boolean type = ($Boolean) column;
        return new Type(table, column, isPrimary, data.BOOLEAN.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    if (column instanceof $Enum) {
        final $Enum type = ($Enum) column;
        return new Type(table, column, isPrimary, data.ENUM.class, commonParams, type.getDefault$() == null ? null : getClassNameOfEnum(table, type).append('.').append(enumStringToEnum(type.getDefault$().text())), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    throw new IllegalArgumentException("Unknown type: " + cls);
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal) org.jaxdb.jsql.data(org.jaxdb.jsql.data) GeneratorExecutionException(org.jaxdb.ddlx.GeneratorExecutionException) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)

Example 18 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row 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;
    }
}
Also used : Builder(com.google.bigtable.v1.RowFilter.Chain.Builder) ReadRowsRequest(com.google.bigtable.v1.ReadRowsRequest) ByteString(com.google.bigtable.repackaged.com.google.protobuf.ByteString) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) RowFilter(com.google.bigtable.v1.RowFilter) Column(com.google.bigtable.v1.Column) Family(com.google.bigtable.v1.Family) DeleteFromRow(com.google.bigtable.v1.Mutation.DeleteFromRow) Row(com.google.bigtable.v1.Row) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row 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;
    }
}
Also used : HashMap(java.util.HashMap) Builder(com.google.bigtable.v1.RowFilter.Chain.Builder) ReadRowsRequest(com.google.bigtable.v1.ReadRowsRequest) ByteString(com.google.bigtable.repackaged.com.google.protobuf.ByteString) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) RowFilter(com.google.bigtable.v1.RowFilter) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) RowRange(com.google.bigtable.v1.RowRange) Column(com.google.bigtable.v1.Column) Family(com.google.bigtable.v1.Family) DeleteFromRow(com.google.bigtable.v1.Mutation.DeleteFromRow) Row(com.google.bigtable.v1.Row) ExecutionException(java.util.concurrent.ExecutionException)

Example 20 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row 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().setStartKeyClosed(ByteStringer.wrap(startkey.getBytes())).build();
    final RowSet rowSet = RowSet.newBuilder().addRowRanges(range).build();
    final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRows(rowSet);
    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;
    }
}
Also used : HashMap(java.util.HashMap) Builder(com.google.bigtable.v2.RowFilter.Chain.Builder) RowSet(com.google.bigtable.v2.RowSet) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) ByteString(com.google.protobuf.ByteString) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowFilter(com.google.bigtable.v2.RowFilter) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowRange(com.google.bigtable.v2.RowRange) Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Row(com.google.bigtable.v2.Row) DeleteFromRow(com.google.bigtable.v2.Mutation.DeleteFromRow) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Test (org.junit.Test)68 Row (org.molgenis.emx2.Row)43 Row (com.google.bigtable.v2.Row)22 ArrayList (java.util.ArrayList)18 ByteString (com.google.protobuf.ByteString)14 Table (org.molgenis.emx2.Table)11 Function (com.google.common.base.Function)10 Row (org.hypertrace.entity.query.service.v1.Row)10 Map (java.util.Map)9 ResultSetChunk (org.hypertrace.entity.query.service.v1.ResultSetChunk)8 Schema (org.molgenis.emx2.Schema)8 Row (com.google.api.ads.admanager.axis.v202108.Row)6 Family (com.google.bigtable.v2.Family)6 List (java.util.List)6 ByteKey (org.apache.beam.sdk.io.range.ByteKey)6 Row (com.google.api.ads.admanager.axis.v202105.Row)5 Row (com.google.api.ads.admanager.axis.v202111.Row)5 Row (com.google.api.ads.admanager.axis.v202202.Row)5 Row (com.google.api.ads.admanager.axis.v202205.Row)5 Row (com.google.api.ads.admanager.jaxws.v202108.Row)5