Search in sources :

Example 1 with BytesEncoder

use of org.apache.hadoop.hbase.spark.datasources.BytesEncoder in project hbase by apache.

the class SparkSQLPushDownFilter method parseFrom.

/**
   * @param pbBytes A pb serialized instance
   * @return An instance of SparkSQLPushDownFilter
   * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
   */
@SuppressWarnings("unused")
public static SparkSQLPushDownFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    SparkFilterProtos.SQLPredicatePushDownFilter proto;
    try {
        proto = SparkFilterProtos.SQLPredicatePushDownFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    String encoder = proto.getEncoderClassName();
    BytesEncoder enc = JavaBytesEncoder.create(encoder);
    //Load DynamicLogicExpression
    DynamicLogicExpression dynamicLogicExpression = DynamicLogicExpressionBuilder.build(proto.getDynamicLogicExpression(), enc);
    //Load valuesFromQuery
    final List<ByteString> valueFromQueryArrayList = proto.getValueFromQueryArrayList();
    byte[][] valueFromQueryArray = new byte[valueFromQueryArrayList.size()][];
    for (int i = 0; i < valueFromQueryArrayList.size(); i++) {
        valueFromQueryArray[i] = valueFromQueryArrayList.get(i).toByteArray();
    }
    //Load mapping from HBase family/qualifier to Spark SQL columnName
    HashMap<ByteArrayComparable, HashMap<ByteArrayComparable, String>> currentCellToColumnIndexMap = new HashMap<>();
    for (SparkFilterProtos.SQLPredicatePushDownCellToColumnMapping sqlPredicatePushDownCellToColumnMapping : proto.getCellToColumnMappingList()) {
        byte[] familyArray = sqlPredicatePushDownCellToColumnMapping.getColumnFamily().toByteArray();
        ByteArrayComparable familyByteComparable = new ByteArrayComparable(familyArray, 0, familyArray.length);
        HashMap<ByteArrayComparable, String> qualifierMap = currentCellToColumnIndexMap.get(familyByteComparable);
        if (qualifierMap == null) {
            qualifierMap = new HashMap<>();
            currentCellToColumnIndexMap.put(familyByteComparable, qualifierMap);
        }
        byte[] qualifierArray = sqlPredicatePushDownCellToColumnMapping.getQualifier().toByteArray();
        ByteArrayComparable qualifierByteComparable = new ByteArrayComparable(qualifierArray, 0, qualifierArray.length);
        qualifierMap.put(qualifierByteComparable, sqlPredicatePushDownCellToColumnMapping.getColumnName());
    }
    return new SparkSQLPushDownFilter(dynamicLogicExpression, valueFromQueryArray, currentCellToColumnIndexMap, encoder);
}
Also used : HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) SparkFilterProtos(org.apache.hadoop.hbase.spark.protobuf.generated.SparkFilterProtos) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ByteString(com.google.protobuf.ByteString) BytesEncoder(org.apache.hadoop.hbase.spark.datasources.BytesEncoder) JavaBytesEncoder(org.apache.hadoop.hbase.spark.datasources.JavaBytesEncoder) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 HashMap (java.util.HashMap)1 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)1 BytesEncoder (org.apache.hadoop.hbase.spark.datasources.BytesEncoder)1 JavaBytesEncoder (org.apache.hadoop.hbase.spark.datasources.JavaBytesEncoder)1 SparkFilterProtos (org.apache.hadoop.hbase.spark.protobuf.generated.SparkFilterProtos)1