Search in sources :

Example 66 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class KuduStoreMetadataAnalyzer method getTableInfo.

@Override
public KuduTableMetadata getTableInfo(String tableName) throws GoraException {
    try {
        KuduTable openTable = client.openTable(tableName);
        List<ColumnSchema> columns = openTable.getSchema().getColumns();
        HashMap<String, String> columnas = new HashMap();
        String pk = "";
        String pkType = "";
        for (ColumnSchema esquema : columns) {
            if (esquema.isKey()) {
                pk = esquema.getName();
                pkType = esquema.getType().getName();
            } else {
                columnas.put(esquema.getName(), esquema.getType().getName());
            }
        }
        return new KuduTableMetadata(pk, pkType, columnas);
    } catch (KuduException ex) {
        throw new GoraException(ex);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) HashMap(java.util.HashMap) KuduTable(org.apache.kudu.client.KuduTable) ColumnSchema(org.apache.kudu.ColumnSchema) KuduException(org.apache.kudu.client.KuduException)

Example 67 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class KuduStore method delete.

@Override
public boolean delete(K key) throws GoraException {
    try {
        Column pkc = kuduMapping.getPrimaryKey().get(0);
        Delete delete = table.newDelete();
        PartialRow row = delete.getRow();
        KuduClientUtils.addObjectRow(row, pkc, key);
        OperationResponse apply = session.apply(delete);
        return !apply.hasRowError();
    } catch (KuduException ex) {
        throw new GoraException(ex);
    }
}
Also used : Delete(org.apache.kudu.client.Delete) GoraException(org.apache.gora.util.GoraException) Column(org.apache.gora.kudu.mapping.Column) PartialRow(org.apache.kudu.client.PartialRow) OperationResponse(org.apache.kudu.client.OperationResponse) KuduException(org.apache.kudu.client.KuduException)

Example 68 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class KuduStore method execute.

@Override
public Result<K, T> execute(Query<K, T> query) throws GoraException {
    String[] avFields = getFieldsToQuery(query.getFields());
    List<String> dbFields = new ArrayList<>();
    for (String af : avFields) {
        dbFields.add(kuduMapping.getFields().get(af).getName());
    }
    try {
        ColumnSchema column = table.getSchema().getColumn(kuduMapping.getPrimaryKey().get(0).getName());
        dbFields.add(kuduMapping.getPrimaryKey().get(0).getName());
        List<KuduPredicate> rangePredicates = KuduClientUtils.createRangePredicate(column, query.getStartKey(), query.getEndKey());
        rangePredicates.add(KuduPredicate.newIsNotNullPredicate(column));
        KuduScanner build = createScanner(rangePredicates, dbFields, query.getLimit());
        return new KuduResult<>(this, query, build);
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) KuduResult(org.apache.gora.kudu.query.KuduResult) KuduScanner(org.apache.kudu.client.KuduScanner) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.kudu.ColumnSchema) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 69 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class KuduStore method put.

@Override
public void put(K key, T obj) throws GoraException {
    try {
        if (obj.isDirty()) {
            Column pkc = kuduMapping.getPrimaryKey().get(0);
            Upsert upsert = table.newUpsert();
            PartialRow row = upsert.getRow();
            KuduClientUtils.addObjectRow(row, pkc, key);
            Schema schemaObj = obj.getSchema();
            List<Schema.Field> fields = schemaObj.getFields();
            for (Schema.Field field : fields) {
                Column mappedColumn = kuduMapping.getFields().get(field.name());
                if (mappedColumn != null) {
                    Object fieldValue = obj.get(field.pos());
                    if (fieldValue != null) {
                        Schema fieldSchema = field.schema();
                        Object serializedObj = serializeFieldValue(fieldSchema, fieldValue);
                        KuduClientUtils.addObjectRow(row, mappedColumn, serializedObj);
                    } else {
                        row.setNull(mappedColumn.getName());
                    }
                } else {
                    throw new GoraException("Unmapped field : " + field.name());
                }
            }
            session.apply(upsert);
        } else {
            LOG.info("Ignored putting object {} in the store as it is neither " + "new, neither dirty.", new Object[] { obj });
        }
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) Upsert(org.apache.kudu.client.Upsert) Column(org.apache.gora.kudu.mapping.Column) ColumnSchema(org.apache.kudu.ColumnSchema) Schema(org.apache.avro.Schema) PartialRow(org.apache.kudu.client.PartialRow) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 70 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class KuduStore method get.

@Override
public T get(K key, String[] fields) throws GoraException {
    String[] avFields = getFieldsToQuery(fields);
    List<String> dbFields = new ArrayList<>();
    for (String af : avFields) {
        dbFields.add(kuduMapping.getFields().get(af).getName());
    }
    try {
        ColumnSchema column = table.getSchema().getColumn(kuduMapping.getPrimaryKey().get(0).getName());
        ArrayList<KuduPredicate> equalPredicate = new ArrayList<>();
        equalPredicate.add(KuduClientUtils.createEqualPredicate(column, key));
        KuduScanner build = createScanner(equalPredicate, dbFields, 1);
        RowResult waitGetOneOrZero = KuduClientUtils.waitFirstResult(build);
        T resp = null;
        if (waitGetOneOrZero != null) {
            resp = newInstance(waitGetOneOrZero, fields);
        }
        build.close();
        return resp;
    } catch (Exception ex) {
        throw new GoraException(ex);
    }
}
Also used : RowResult(org.apache.kudu.client.RowResult) GoraException(org.apache.gora.util.GoraException) KuduScanner(org.apache.kudu.client.KuduScanner) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.kudu.ColumnSchema) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Aggregations

GoraException (org.apache.gora.util.GoraException)174 IOException (java.io.IOException)119 ArrayList (java.util.ArrayList)30 Schema (org.apache.avro.Schema)25 SQLException (java.sql.SQLException)17 HashMap (java.util.HashMap)17 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 PreparedStatement (java.sql.PreparedStatement)11 Map (java.util.Map)11 PersistentBase (org.apache.gora.persistency.impl.PersistentBase)9 SolrServerException (org.apache.solr.client.solrj.SolrServerException)9 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)8 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)8 Field (org.apache.avro.Schema.Field)8 KuduException (org.apache.kudu.client.KuduException)8 ResultSet (com.datastax.driver.core.ResultSet)7 SimpleStatement (com.datastax.driver.core.SimpleStatement)7 SAXBuilder (org.jdom.input.SAXBuilder)7 InputStream (java.io.InputStream)6