Java Code Examples for org.apache.kylin.common.util.BytesUtil#EMPTY_BYTE_ARRAY

The following examples show how to use org.apache.kylin.common.util.BytesUtil#EMPTY_BYTE_ARRAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HBaseResourceStore.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void putSmallResource(String resPath, ContentWriter content, long ts) throws IOException {
    byte[] row = Bytes.toBytes(resPath);
    byte[] bytes = content.extractAllBytes();

    Table table = getConnection().getTable(TableName.valueOf(tableName));
    RollbackablePushdown pushdown = null;
    try {
        if (bytes.length > kvSizeLimit) {
            pushdown = writePushdown(resPath, ContentWriter.create(bytes));
            bytes = BytesUtil.EMPTY_BYTE_ARRAY;
        }

        Put put = new Put(row);
        put.addColumn(B_FAMILY, B_COLUMN, bytes);
        put.addColumn(B_FAMILY, B_COLUMN_TS, Bytes.toBytes(ts));

        table.put(put);

    } catch (Exception ex) {
        if (pushdown != null)
            pushdown.rollback();
        throw ex;
    } finally {
        if (pushdown != null)
            pushdown.close();
        IOUtils.closeQuietly(table);
    }
}
 
Example 2
Source File: HBaseResourceStore.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected void putSmallResource(String resPath, ContentWriter content, long ts) throws IOException {
    byte[] row = Bytes.toBytes(resPath);
    byte[] bytes = content.extractAllBytes();

    Table table = getConnection().getTable(TableName.valueOf(tableName));
    RollbackablePushdown pushdown = null;
    try {
        if (bytes.length > kvSizeLimit) {
            pushdown = writePushdown(resPath, ContentWriter.create(bytes));
            bytes = BytesUtil.EMPTY_BYTE_ARRAY;
        }

        Put put = new Put(row);
        put.addColumn(B_FAMILY, B_COLUMN, bytes);
        put.addColumn(B_FAMILY, B_COLUMN_TS, Bytes.toBytes(ts));

        table.put(put);

    } catch (Exception ex) {
        if (pushdown != null)
            pushdown.rollback();
        throw ex;
    } finally {
        if (pushdown != null)
            pushdown.close();
        IOUtils.closeQuietly(table);
    }
}
 
Example 3
Source File: CompressedValueContainer.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public void fromBytes(ImmutableBytesWritable bytes) {
    try {
        uncompressed = LZFDecoder.decode(bytes.get(), bytes.getOffset(), bytes.getLength());
    } catch (IOException e) {
        throw new RuntimeException("LZF decode failure", e);
    }
    size = cap = uncompressed.length / valueLen;
    compressed = BytesUtil.EMPTY_BYTE_ARRAY; // mark closed
}
 
Example 4
Source File: BitMapContainer.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private ImmutableBytesWritable setToBytes(ConciseSet set) {
    byte[] array;
    if (set.isEmpty()) // ConciseSet.toByteBuffer() throws exception when
                       // set is empty
        array = BytesUtil.EMPTY_BYTE_ARRAY;
    else
        array = set.toByteBuffer().array();
    return new ImmutableBytesWritable(array);
}
 
Example 5
Source File: HBaseResourceStore.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private Put buildPut(String resPath, long ts, byte[] row, byte[] content, HTableInterface table) throws IOException {
    int kvSizeLimit = this.kylinConfig.getHBaseKeyValueSize();
    if (content.length > kvSizeLimit) {
        writeLargeCellToHdfs(resPath, content, table);
        content = BytesUtil.EMPTY_BYTE_ARRAY;
    }

    Put put = new Put(row);
    put.add(B_FAMILY, B_COLUMN, content);
    put.add(B_FAMILY, B_COLUMN_TS, Bytes.toBytes(ts));

    return put;
}
 
Example 6
Source File: HBaseResourceStore.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
protected long checkAndPutResourceImpl(String resPath, byte[] content, long oldTS, long newTS)
        throws IOException, IllegalStateException {
    Table table = getConnection().getTable(TableName.valueOf(tableName));
    RollbackablePushdown pushdown = null;
    try {
        byte[] row = Bytes.toBytes(resPath);
        byte[] bOldTS = oldTS == 0 ? null : Bytes.toBytes(oldTS);

        if (content.length > kvSizeLimit) {
            pushdown = writePushdown(resPath, ContentWriter.create(content));
            content = BytesUtil.EMPTY_BYTE_ARRAY;
        }

        Put put = new Put(row);
        put.addColumn(B_FAMILY, B_COLUMN, content);
        put.addColumn(B_FAMILY, B_COLUMN_TS, Bytes.toBytes(newTS));

        boolean ok = table.checkAndPut(row, B_FAMILY, B_COLUMN_TS, bOldTS, put);
        logger.trace("Update row {} from oldTs: {}, to newTs: {}, operation result: {}", resPath, oldTS, newTS, ok);
        if (!ok) {
            long real = getResourceTimestampImpl(resPath);
            throw new WriteConflictException(
                    "Overwriting conflict " + resPath +
                            ", expect old TS " + oldTS +
                            ", but it is " + real +
                            ", the expected new TS: " + newTS);
        }

        return newTS;

    } catch (Exception ex) {
        if (pushdown != null)
            pushdown.rollback();
        throw ex;
    } finally {
        if (pushdown != null)
            pushdown.close();
        IOUtils.closeQuietly(table);
    }
}
 
Example 7
Source File: CoprocessorFilter.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public static byte[] serialize(CoprocessorFilter o) {
    return (o.filter == null) ? BytesUtil.EMPTY_BYTE_ARRAY : TupleFilterSerializer.serialize(o.filter, DictCodeSystem.INSTANCE);
}
 
Example 8
Source File: HBaseResourceStore.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
protected long checkAndPutResourceImpl(String resPath, byte[] content, long oldTS, long newTS)
        throws IOException, IllegalStateException {
    Table table = getConnection().getTable(TableName.valueOf(tableName));
    RollbackablePushdown pushdown = null;
    try {
        byte[] row = Bytes.toBytes(resPath);
        byte[] bOldTS = oldTS == 0 ? null : Bytes.toBytes(oldTS);

        if (content.length > kvSizeLimit) {
            pushdown = writePushdown(resPath, ContentWriter.create(content));
            content = BytesUtil.EMPTY_BYTE_ARRAY;
        }

        Put put = new Put(row);
        put.addColumn(B_FAMILY, B_COLUMN, content);
        put.addColumn(B_FAMILY, B_COLUMN_TS, Bytes.toBytes(newTS));

        boolean ok = table.checkAndPut(row, B_FAMILY, B_COLUMN_TS, bOldTS, put);
        logger.trace("Update row {} from oldTs: {}, to newTs: {}, operation result: {}", resPath, oldTS, newTS, ok);
        if (!ok) {
            long real = getResourceTimestampImpl(resPath);
            throw new WriteConflictException(
                    "Overwriting conflict " + resPath +
                            ", expect old TS " + oldTS +
                            ", but it is " + real +
                            ", the expected new TS: " + newTS);
        }

        return newTS;

    } catch (Exception ex) {
        if (pushdown != null)
            pushdown.rollback();
        throw ex;
    } finally {
        if (pushdown != null)
            pushdown.close();
        IOUtils.closeQuietly(table);
    }
}
 
Example 9
Source File: CoprocessorFilter.java    From kylin with Apache License 2.0 4 votes vote down vote up
public static byte[] serialize(CoprocessorFilter o) {
    return (o.filter == null) ? BytesUtil.EMPTY_BYTE_ARRAY : TupleFilterSerializer.serialize(o.filter, DictCodeSystem.INSTANCE);
}
 
Example 10
Source File: CoprocessorFilter.java    From Kylin with Apache License 2.0 4 votes vote down vote up
public static byte[] serialize(CoprocessorFilter o) {
    return (o.filter == null) ? BytesUtil.EMPTY_BYTE_ARRAY : TupleFilterSerializer.serialize(o.filter);
}