List of usage examples for org.apache.hadoop.io WritableUtils writeVInt
public static void writeVInt(DataOutput stream, int i) throws IOException
From source file:org.apache.nutch.scoring.ScoreDatum.java
License:Apache License
@Override public void write(DataOutput out) throws IOException { out.writeFloat(score);//w w w. j av a 2s. c om Text.writeString(out, url); Text.writeString(out, anchor); WritableUtils.writeVInt(out, distance); WritableUtils.writeVInt(out, metaData.size()); for (Entry<String, byte[]> e : metaData.entrySet()) { Text.writeString(out, e.getKey()); Bytes.writeByteArray(out, e.getValue()); } }
From source file:org.apache.nutch.searcher.QueryParams.java
License:Apache License
@Override public void write(DataOutput output) throws IOException { metadata.write(output);//from www .j ava2s.co m WritableUtils.writeVInt(output, numHits); WritableUtils.writeVInt(output, maxHitsPerDup); WritableUtils.writeString(output, dedupField); WritableUtils.writeString(output, sortField); output.writeBoolean(reverse); }
From source file:org.apache.phoenix.cache.aggcache.SpillManager.java
License:Apache License
private byte[] serialize(ImmutableBytesPtr key, Aggregator[] aggs, ServerAggregators serverAggs) throws IOException { DataOutputStream output = null; ByteArrayOutputStream bai = null; try {//w ww . j a v a 2 s .c om bai = new ByteArrayOutputStream(); output = new DataOutputStream(bai); // key length WritableUtils.writeVInt(output, key.getLength()); // key output.write(key.get(), key.getOffset(), key.getLength()); byte[] aggsByte = serverAggs.toBytes(aggs); // aggs length WritableUtils.writeVInt(output, aggsByte.length); // aggs output.write(aggsByte); return bai.toByteArray(); } finally { if (bai != null) { bai.close(); bai = null; } if (output != null) { output.close(); output = null; } } }
From source file:org.apache.phoenix.compile.ProjectionCompiler.java
License:Apache License
private static void serailizeArrayIndexInformationAndSetInScan(StatementContext context, List<Expression> arrayKVFuncs, List<KeyValueColumnExpression> arrayKVRefs) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try {/* w w w . j a v a 2 s . c om*/ DataOutputStream output = new DataOutputStream(stream); // Write the arrayKVRef size followed by the keyvalues that needs to be of type arrayindex function WritableUtils.writeVInt(output, arrayKVRefs.size()); for (Expression expression : arrayKVRefs) { expression.write(output); } // then write the number of arrayindex functions followeed by the expression itself WritableUtils.writeVInt(output, arrayKVFuncs.size()); for (Expression expression : arrayKVFuncs) { expression.write(output); } } catch (IOException e) { throw new RuntimeException(e); } finally { try { stream.close(); } catch (IOException e) { throw new RuntimeException(e); } } context.getScan().setAttribute(BaseScannerRegionObserver.SPECIFIC_ARRAY_INDEX, stream.toByteArray()); }
From source file:org.apache.phoenix.coprocessor.GroupedAggregateRegionObserver.java
License:Apache License
public static void serializeIntoScan(Scan scan, String attribName, List<Expression> groupByExpressions) { ByteArrayOutputStream stream = new ByteArrayOutputStream(Math.max(1, groupByExpressions.size() * 10)); try {//w w w . j av a 2s. c o m if (groupByExpressions.isEmpty()) { // FIXME ? stream.write(QueryConstants.TRUE); } else { DataOutputStream output = new DataOutputStream(stream); for (Expression expression : groupByExpressions) { WritableUtils.writeVInt(output, ExpressionType.valueOf(expression).ordinal()); expression.write(output); } } } catch (IOException e) { throw new RuntimeException(e); // Impossible } finally { try { stream.close(); } catch (IOException e) { throw new RuntimeException(e); } } scan.setAttribute(attribName, stream.toByteArray()); }
From source file:org.apache.phoenix.coprocessor.ScanRegionObserver.java
License:Apache License
public static void serializeIntoScan(Scan scan, int thresholdBytes, int limit, List<OrderByExpression> orderByExpressions, int estimatedRowSize) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); // TODO: size? try {/*from w w w . ja va2 s . co m*/ DataOutputStream output = new DataOutputStream(stream); WritableUtils.writeVInt(output, thresholdBytes); WritableUtils.writeVInt(output, limit); WritableUtils.writeVInt(output, estimatedRowSize); WritableUtils.writeVInt(output, orderByExpressions.size()); for (OrderByExpression orderingCol : orderByExpressions) { orderingCol.write(output); } scan.setAttribute(BaseScannerRegionObserver.TOPN, stream.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } finally { try { stream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver.java
License:Apache License
public static byte[] serialize(List<Expression> selectExpressions) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try {// w w w. ja va 2s .c o m DataOutputStream output = new DataOutputStream(stream); WritableUtils.writeVInt(output, selectExpressions.size()); for (int i = 0; i < selectExpressions.size(); i++) { Expression expression = selectExpressions.get(i); WritableUtils.writeVInt(output, ExpressionType.valueOf(expression).ordinal()); expression.write(output); } return stream.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } finally { try { stream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:org.apache.phoenix.execute.BaseQueryPlan.java
License:Apache License
private void serializeViewConstantsIntoScan(byte[][] viewConstants, Scan scan) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try {/*from w w w . j a va 2 s. com*/ DataOutputStream output = new DataOutputStream(stream); WritableUtils.writeVInt(output, viewConstants.length); for (byte[] viewConstant : viewConstants) { Bytes.writeByteArray(output, viewConstant); } scan.setAttribute(BaseScannerRegionObserver.VIEW_CONSTANTS, stream.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } finally { try { stream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:org.apache.phoenix.execute.BaseQueryPlan.java
License:Apache License
private void serializeDataTableColumnsToJoin(Scan scan, Set<PColumn> dataColumns, PTable dataTable) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try {//from w w w. ja va 2s. c om DataOutputStream output = new DataOutputStream(stream); boolean storeColsInSingleCell = dataTable .getImmutableStorageScheme() == ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS; if (storeColsInSingleCell) { // if storeColsInSingleCell is true all columns of a given column family are stored in a single cell scan.setAttribute(BaseScannerRegionObserver.COLUMNS_STORED_IN_SINGLE_CELL, QueryConstants.EMPTY_COLUMN_VALUE_BYTES); } WritableUtils.writeVInt(output, dataColumns.size()); for (PColumn column : dataColumns) { byte[] cf = column.getFamilyName().getBytes(); byte[] cq = column.getColumnQualifierBytes(); Bytes.writeByteArray(output, cf); Bytes.writeByteArray(output, cq); } scan.setAttribute(BaseScannerRegionObserver.DATA_TABLE_COLUMNS_TO_JOIN, stream.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } finally { try { stream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:org.apache.phoenix.execute.TupleProjector.java
License:Apache License
public static void serializeProjectorIntoScan(Scan scan, TupleProjector projector) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try {// ww w. jav a 2s . c o m DataOutputStream output = new DataOutputStream(stream); projector.schema.write(output); int count = projector.expressions.length; WritableUtils.writeVInt(output, count); for (int i = 0; i < count; i++) { WritableUtils.writeVInt(output, ExpressionType.valueOf(projector.expressions[i]).ordinal()); projector.expressions[i].write(output); } scan.setAttribute(SCAN_PROJECTOR, stream.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } finally { try { stream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }