Java Code Examples for org.apache.hadoop.hbase.util.Bytes#toBoolean()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#toBoolean() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: phoenix-omid   File: OmidSnapshotFilter.java    License: Apache License 2.0 6 votes vote down vote up
public void preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> e,
                           Scan scan) throws IOException {
    byte[] byteTransaction = scan.getAttribute(CellUtils.TRANSACTION_ATTRIBUTE);

    if (byteTransaction == null) {
        return;
    }
    boolean isLowLatency = Bytes.toBoolean(scan.getAttribute(CellUtils.LL_ATTRIBUTE));
    HBaseTransaction hbaseTransaction = getHBaseTransaction(byteTransaction, isLowLatency);
    SnapshotFilterImpl snapshotFilter = getSnapshotFilter(e);

    scan.setMaxVersions();
    Filter newFilter = TransactionFilters.getVisibilityFilter(scan.getFilter(),
            snapshotFilter, hbaseTransaction);
    scan.setFilter(newFilter);
    return;
}
 
Example 2
public Object toValue( byte[] bytes )
{
  final SupportType type = getType();
  switch (type) {
    case BOOLEAN:
      return Bytes.toBoolean( bytes );
    case SHORT:
      return Bytes.toShort( bytes );
    case INTEGER:
      return Bytes.toInt( bytes );
    case LONG:
      return Bytes.toLong( bytes );
    case FLOAT:
      return Bytes.toFloat( bytes );
    case DOUBLE:
      return Bytes.toDouble( bytes );
    case STRING:
      return Bytes.toString( bytes );
    default:
      throw new IllegalArgumentException("Unsupported type: " + type);
  }
}
 
Example 3
Source Project: spork   File: HBaseBinaryConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Boolean bytesToBoolean(byte[] b) throws IOException {
    if (Bytes.SIZEOF_BOOLEAN > b.length) {
        return Bytes.toBoolean(Bytes.padHead(b, Bytes.SIZEOF_BOOLEAN - b.length));
    } else {
        return Bytes.toBoolean(Bytes.head(b, Bytes.SIZEOF_BOOLEAN));
    }
}
 
Example 4
Source Project: flink   File: HBaseTypeUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Deserialize byte array to Java Object with the given type.
 */
public static Object deserializeToObject(byte[] value, int typeIdx, Charset stringCharset) {
	switch (typeIdx) {
		case 0: // byte[]
			return value;
		case 1: // String
			return new String(value, stringCharset);
		case 2: // byte
			return value[0];
		case 3:
			return Bytes.toShort(value);
		case 4:
			return Bytes.toInt(value);
		case 5:
			return Bytes.toLong(value);
		case 6:
			return Bytes.toFloat(value);
		case 7:
			return Bytes.toDouble(value);
		case 8:
			return Bytes.toBoolean(value);
		case 9: // sql.Timestamp encoded as long
			return new Timestamp(Bytes.toLong(value));
		case 10: // sql.Date encoded as long
			return new Date(Bytes.toLong(value));
		case 11: // sql.Time encoded as long
			return new Time(Bytes.toLong(value));
		case 12:
			return Bytes.toBigDecimal(value);
		case 13:
			return new BigInteger(value);

		default:
			throw new IllegalArgumentException("unsupported type index:" + typeIdx);
	}
}
 
Example 5
Source Project: DataLink   File: MultiVersionTask.java    License: Apache License 2.0 5 votes vote down vote up
private Column convertBytesToAssignType(ColumnType columnType, byte[] byteArray) throws UnsupportedEncodingException {
    Column column;
    switch (columnType) {
        case BOOLEAN:
            column = new BoolColumn(byteArray == null ? null : Bytes.toBoolean(byteArray));
            break;
        case SHORT:
            column = new LongColumn(byteArray == null ? null : String.valueOf(Bytes.toShort(byteArray)));
            break;
        case INT:
            column = new LongColumn(byteArray == null ? null : Bytes.toInt(byteArray));
            break;
        case LONG:
            column = new LongColumn(byteArray == null ? null : Bytes.toLong(byteArray));
            break;
        case BYTES:
            column = new BytesColumn(byteArray);
            break;
        case FLOAT:
            column = new DoubleColumn(byteArray == null ? null : Bytes.toFloat(byteArray));
            break;
        case DOUBLE:
            column = new DoubleColumn(byteArray == null ? null : Bytes.toDouble(byteArray));
            break;
        case STRING:
            column = new StringColumn(byteArray == null ? null : new String(byteArray, super.encoding));
            break;
        case BINARY_STRING:
            column = new StringColumn(byteArray == null ? null : Bytes.toStringBinary(byteArray));
            break;

        default:
            throw DataXException.asDataXException(HbaseReaderErrorCode.ILLEGAL_VALUE, "Hbasereader 不支持您配置的列类型:" + columnType);
    }

    return column;
}
 
Example 6
@Override
public boolean getBoolean(int field)
{
    checkFieldType(field, BOOLEAN);
    byte[] bytes = getValue(field);
    return Bytes.toBoolean(bytes);
}
 
Example 7
Source Project: phoenix-omid   File: OmidSnapshotFilter.java    License: Apache License 2.0 5 votes vote down vote up
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
        throws IOException {

    if (get.getAttribute(CellUtils.CLIENT_GET_ATTRIBUTE) == null) return;
    boolean isLowLatency = Bytes.toBoolean(get.getAttribute(CellUtils.LL_ATTRIBUTE));
    HBaseTransaction hbaseTransaction = getHBaseTransaction(get.getAttribute(CellUtils.TRANSACTION_ATTRIBUTE),
            isLowLatency);
    SnapshotFilterImpl snapshotFilter = getSnapshotFilter(e);
    snapshotFilterMap.put(get, snapshotFilter);

    get.setMaxVersions();
    Filter newFilter = TransactionFilters.getVisibilityFilter(get.getFilter(),
            snapshotFilter, hbaseTransaction);
    get.setFilter(newFilter);
}
 
Example 8
Source Project: SpyGlass   File: HBaseTableSplitBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
    LOG.debug("READ ME : " + in.toString());

    this.m_tableName = Bytes.readByteArray(in);
    this.m_regionLocation = Bytes.toString(Bytes.readByteArray(in));
    this.m_regionName = Bytes.toString(Bytes.readByteArray(in));
    this.m_sourceMode = HBaseConstants.SourceMode.valueOf(Bytes.toString(Bytes
            .readByteArray(in)));
    this.m_useSalt = Bytes.toBoolean(Bytes.readByteArray(in));

    switch (this.m_sourceMode) {
        case SCAN_RANGE:
            this.m_startRow = Bytes.readByteArray(in);
            this.m_endRow = Bytes.readByteArray(in);
            this.m_endRowInclusive = Bytes.toBoolean(Bytes.readByteArray(in));
            break;

        case GET_LIST:
            this.m_versions = Bytes.toInt(Bytes.readByteArray(in));
            this.m_keyList = new TreeSet<String>();

            int m = Bytes.toInt(Bytes.readByteArray(in));

            for (int i = 0; i < m; i++) {
                this.m_keyList.add(Bytes.toString(Bytes.readByteArray(in)));
            }
            break;
    }

    this.m_timestamp = Bytes.toLong(Bytes.readByteArray(in));

    LOG.debug("READ and CREATED : " + this);
}
 
Example 9
Source Project: flink   File: HBaseTypeUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Deserialize byte array to Java Object with the given type.
 */
public static Object deserializeToObject(byte[] value, int typeIdx, Charset stringCharset) {
	switch (typeIdx) {
		case 0: // byte[]
			return value;
		case 1: // String
			return Arrays.equals(EMPTY_BYTES, value) ? null : new String(value, stringCharset);
		case 2: // byte
			return value[0];
		case 3:
			return Bytes.toShort(value);
		case 4:
			return Bytes.toInt(value);
		case 5:
			return Bytes.toLong(value);
		case 6:
			return Bytes.toFloat(value);
		case 7:
			return Bytes.toDouble(value);
		case 8:
			return Bytes.toBoolean(value);
		case 9: // sql.Timestamp encoded as long
			return new Timestamp(Bytes.toLong(value));
		case 10: // sql.Date encoded as long
			return new Date(Bytes.toLong(value));
		case 11: // sql.Time encoded as long
			return new Time(Bytes.toLong(value));
		case 12:
			return Bytes.toBigDecimal(value);
		case 13:
			return new BigInteger(value);

		default:
			throw new IllegalArgumentException("unsupported type index:" + typeIdx);
	}
}
 
Example 10
Source Project: hbase   File: MobUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether it's a raw scan. The information is set in the attribute "hbase.mob.scan.raw"
 * of scan. For a mob cell, in a normal scan the scanners retrieves the mob cell from the mob
 * file. In a raw scan, the scanner directly returns cell in HBase without retrieve the one in the
 * mob file.
 * @param scan The current scan.
 * @return True if it's a raw scan.
 */
public static boolean isRawMobScan(Scan scan) {
  byte[] raw = scan.getAttribute(MobConstants.MOB_SCAN_RAW);
  try {
    return raw != null && Bytes.toBoolean(raw);
  } catch (IllegalArgumentException e) {
    return false;
  }
}
 
Example 11
Source Project: Kylin   File: AclService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> oids, List<Sid> sids) throws NotFoundException {
    Map<ObjectIdentity, Acl> aclMaps = new HashMap<ObjectIdentity, Acl>();
    HTableInterface htable = null;
    Result result = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName);

        for (ObjectIdentity oid : oids) {
            result = htable.get(new Get(Bytes.toBytes(String.valueOf(oid.getIdentifier()))));

            if (null != result && !result.isEmpty()) {
                SidInfo owner = sidSerializer.deserialize(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_OWNER_COLUMN)));
                Sid ownerSid = (null == owner) ? null : (owner.isPrincipal() ? new PrincipalSid(owner.getSid()) : new GrantedAuthoritySid(owner.getSid()));
                boolean entriesInheriting = Bytes.toBoolean(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_ENTRY_INHERIT_COLUMN)));

                Acl parentAcl = null;
                DomainObjectInfo parentInfo = domainObjSerializer.deserialize(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_PARENT_COLUMN)));
                if (null != parentInfo) {
                    ObjectIdentity parentObj = new ObjectIdentityImpl(parentInfo.getType(), parentInfo.getId());
                    parentAcl = readAclById(parentObj, null);
                }

                AclImpl acl = new AclImpl(oid, oid.getIdentifier(), aclAuthorizationStrategy, permissionGrantingStrategy, parentAcl, null, entriesInheriting, ownerSid);
                genAces(sids, result, acl);

                aclMaps.put(oid, acl);
            } else {
                throw new NotFoundException("Unable to find ACL information for object identity '" + oid + "'");
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }

    return aclMaps;
}
 
Example 12
Source Project: hbase   File: MobUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether the scan contains the information of caching blocks. The information is set
 * in the attribute "hbase.mob.cache.blocks" of scan.
 * @param scan The current scan.
 * @return True when the Scan attribute specifies to cache the MOB blocks.
 */
public static boolean isCacheMobBlocks(Scan scan) {
  byte[] cache = scan.getAttribute(MobConstants.MOB_CACHE_BLOCKS);
  try {
    return cache != null && Bytes.toBoolean(cache);
  } catch (IllegalArgumentException e) {
    return false;
  }
}
 
Example 13
Source Project: hbase   File: MobUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether return null value when the mob file is missing or corrupt. The information is
 * set in the attribute "empty.value.on.mobcell.miss" of scan.
 * @param scan The current scan.
 * @return True if the readEmptyValueOnMobCellMiss is enabled.
 */
public static boolean isReadEmptyValueOnMobCellMiss(Scan scan) {
  byte[] readEmptyValueOnMobCellMiss =
      scan.getAttribute(MobConstants.EMPTY_VALUE_ON_MOBCELL_MISS);
  try {
    return readEmptyValueOnMobCellMiss != null && Bytes.toBoolean(readEmptyValueOnMobCellMiss);
  } catch (IllegalArgumentException e) {
    return false;
  }
}
 
Example 14
Source Project: hbase   File: HFileInfo.java    License: Apache License 2.0 5 votes vote down vote up
private void loadMetaInfo(HFileBlock.BlockIterator blockIter, HFileContext hfileContext)
    throws IOException {
  read(blockIter.nextBlockWithBlockType(BlockType.FILE_INFO).getByteStream());
  byte[] creationTimeBytes = get(HFileInfo.CREATE_TIME_TS);
  hfileContext.setFileCreateTime(creationTimeBytes == null ?
      0 : Bytes.toLong(creationTimeBytes));
  byte[] tmp = get(HFileInfo.MAX_TAGS_LEN);
  // max tag length is not present in the HFile means tags were not at all written to file.
  if (tmp != null) {
    hfileContext.setIncludesTags(true);
    tmp = get(HFileInfo.TAGS_COMPRESSED);
    if (tmp != null && Bytes.toBoolean(tmp)) {
      hfileContext.setCompressTags(true);
    }
  }
  // parse meta info
  if (get(HFileInfo.LASTKEY) != null) {
    lastKeyCell = new KeyValue.KeyOnlyKeyValue(get(HFileInfo.LASTKEY));
  }
  avgKeyLen = Bytes.toInt(get(HFileInfo.AVG_KEY_LEN));
  avgValueLen = Bytes.toInt(get(HFileInfo.AVG_VALUE_LEN));
  byte [] keyValueFormatVersion = get(HFileWriterImpl.KEY_VALUE_VERSION);
  includesMemstoreTS = keyValueFormatVersion != null &&
      Bytes.toInt(keyValueFormatVersion) == HFileWriterImpl.KEY_VALUE_VER_WITH_MEMSTORE;
  hfileContext.setIncludesMvcc(includesMemstoreTS);
  if (includesMemstoreTS) {
    decodeMemstoreTS = Bytes.toLong(get(HFileWriterImpl.MAX_MEMSTORE_TS_KEY)) > 0;
  }
}
 
Example 15
Source Project: hbase   File: Mutation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return current value for returnResults
 */
// Used by Increment and Append only.
@InterfaceAudience.Private
protected boolean isReturnResults() {
  byte[] v = getAttribute(RETURN_RESULTS);
  return v == null ? true : Bytes.toBoolean(v);
}
 
Example 16
@Override
protected Object mapInternal(byte[] input) {
    return Bytes.toBoolean(input);
}
 
Example 17
private RegionScanner collectStats(final RegionScanner innerScanner, StatisticsCollector stats,
        final Region region, final Scan scan, Configuration config) throws IOException {
    StatsCollectionCallable callable =
            new StatsCollectionCallable(stats, region, innerScanner, config, scan);
    byte[] asyncBytes = scan.getAttribute(BaseScannerRegionObserver.RUN_UPDATE_STATS_ASYNC_ATTRIB);
    boolean async = false;
    if (asyncBytes != null) {
        async = Bytes.toBoolean(asyncBytes);
    }
    long rowCount = 0; // in case of async, we report 0 as number of rows updated
    StatisticsCollectionRunTracker statsRunTracker =
            StatisticsCollectionRunTracker.getInstance(config);
    final boolean runUpdateStats = statsRunTracker.addUpdateStatsCommandRegion(region.getRegionInfo(),scan.getFamilyMap().keySet());
    if (runUpdateStats) {
        if (!async) {
            rowCount = callable.call();
        } else {
            statsRunTracker.runTask(callable);
        }
    } else {
        rowCount = CONCURRENT_UPDATE_STATS_ROW_COUNT;
        LOGGER.info("UPDATE STATISTICS didn't run because another UPDATE STATISTICS command was already running on the region "
                + region.getRegionInfo().getRegionNameAsString());
    }
    byte[] rowCountBytes = PLong.INSTANCE.toBytes(Long.valueOf(rowCount));
    final Cell aggKeyValue =
            PhoenixKeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY,
                SINGLE_COLUMN, AGG_TIMESTAMP, rowCountBytes, 0, rowCountBytes.length);
    RegionScanner scanner = new BaseRegionScanner(innerScanner) {
        @Override
        public RegionInfo getRegionInfo() {
            return region.getRegionInfo();
        }

        @Override
        public boolean isFilterDone() {
            return true;
        }

        @Override
        public void close() throws IOException {
            // If we ran/scheduled StatsCollectionCallable the delegate
            // scanner is closed there. Otherwise close it here.
            if (!runUpdateStats) {
                super.close();
            }
        }

        @Override
        public boolean next(List<Cell> results) throws IOException {
            results.add(aggKeyValue);
            return false;
        }

        @Override
        public long getMaxResultSize() {
            return scan.getMaxResultSize();
        }
    };
    return scanner;
}
 
Example 18
protected boolean skipRegionBoundaryCheck(Scan scan) {
    byte[] skipCheckBytes = scan.getAttribute(SKIP_REGION_BOUNDARY_CHECK);
    return skipCheckBytes != null && Bytes.toBoolean(skipCheckBytes);
}
 
Example 19
public DeserializedBooleanComparator( byte[] raw ) {
  super( raw );
  m_value = Bytes.toBoolean( raw );
}
 
Example 20
Source Project: hbase   File: Scan.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return True if collection of scan metrics is enabled. For advanced users.
 */
public boolean isScanMetricsEnabled() {
  byte[] attr = getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE);
  return attr == null ? false : Bytes.toBoolean(attr);
}