Java Code Examples for org.apache.hadoop.hbase.client.Scan#getFamilyMap()

The following examples show how to use org.apache.hadoop.hbase.client.Scan#getFamilyMap() . 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 check out the related API usage on the sidebar.
Example 1
Source Project: phoenix-omid   File: TTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Transactional version of {@link Table#getScanner(Scan scan)}
 *
 * @param scan an instance of Scan
 * @param tx   an instance of transaction to be used
 * @return ResultScanner an instance of ResultScanner
 * @throws IOException if a remote or network exception occurs.
 */
public ResultScanner getScanner(Transaction tx, Scan scan) throws IOException {

    throwExceptionIfOpSetsTimerange(scan);
    flushCommits();
    HBaseTransaction transaction = enforceHBaseTransactionAsParam(tx);

    Scan tsscan = new Scan(scan);
    tsscan.setMaxVersions(1);
    tsscan.setTimeRange(0, transaction.getReadTimestamp() + 1);
    propagateAttributes(scan, tsscan);
    Map<byte[], NavigableSet<byte[]>> kvs = scan.getFamilyMap();
    for (Map.Entry<byte[], NavigableSet<byte[]>> entry : kvs.entrySet()) {
        byte[] family = entry.getKey();
        NavigableSet<byte[]> qualifiers = entry.getValue();
        if (qualifiers == null) {
            continue;
        }
        for (byte[] qualifier : qualifiers) {
            tsscan.addColumn(family, CellUtils.addShadowCellSuffixPrefix(qualifier));
        }
        if (!qualifiers.isEmpty()) {
            tsscan.addColumn(entry.getKey(), CellUtils.FAMILY_DELETE_QUALIFIER);
        }
    }

    return snapshotFilter.getScanner(tsscan, transaction);
}
 
Example 2
Source Project: phoenix   File: IndexUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean containsOneOrMoreColumn(Scan scan) {
    Map<byte[], NavigableSet<byte[]>> familyMap = scan.getFamilyMap();
    if (familyMap == null || familyMap.isEmpty()) {
        return false;
    }
    for (Map.Entry<byte[], NavigableSet<byte[]>> entry : familyMap.entrySet()) {
        NavigableSet<byte[]> family = entry.getValue();
        if (family != null && !family.isEmpty()) {
            return true;
        }
    }
    return false;
}
 
Example 3
public ParallelIterators(StatementContext context, TableRef tableRef, FilterableStatement statement, RowProjector projector, GroupBy groupBy, Integer limit, ParallelIteratorFactory iteratorFactory) throws SQLException {
    super(context, tableRef, groupBy);
    this.splits = getSplits(context, tableRef, statement.getHint());
    this.iteratorFactory = iteratorFactory;
    Scan scan = context.getScan();
    PTable table = tableRef.getTable();
    if (projector.isProjectEmptyKeyValue()) {
        Map<byte [], NavigableSet<byte []>> familyMap = scan.getFamilyMap();
        // If nothing projected into scan and we only have one column family, just allow everything
        // to be projected and use a FirstKeyOnlyFilter to skip from row to row. This turns out to
        // be quite a bit faster.
        if (familyMap.isEmpty() && table.getColumnFamilies().size() == 1) {
            // Project the one column family. We must project a column family since it's possible
            // that there are other non declared column families that we need to ignore.
            scan.addFamily(table.getColumnFamilies().get(0).getName().getBytes());
            ScanUtil.andFilterAtBeginning(scan, new FirstKeyOnlyFilter());
        } else {
            byte[] ecf = SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies());
            // Project empty key value unless the column family containing it has
            // been projected in its entirety.
            if (!familyMap.containsKey(ecf) || familyMap.get(ecf) != null) {
                scan.addColumn(ecf, QueryConstants.EMPTY_COLUMN_BYTES);
            }
        }
    }
    if (limit != null) {
        ScanUtil.andFilterAtEnd(scan, new PageFilter(limit));
    }
}
 
Example 4
Source Project: phoenix   File: BaseResultIterators.java    License: Apache License 2.0 4 votes vote down vote up
public BaseResultIterators(QueryPlan plan, Integer perScanLimit) throws SQLException {
    super(plan.getContext(), plan.getTableRef(), plan.getGroupBy(), plan.getOrderBy(), plan.getStatement().getHint());
    this.plan = plan;
    StatementContext context = plan.getContext();
    TableRef tableRef = plan.getTableRef();
    PTable table = tableRef.getTable();
    FilterableStatement statement = plan.getStatement();
    RowProjector projector = plan.getProjector();
    physicalTableName = table.getPhysicalName().getBytes();
    tableStats = useStats() ? new MetaDataClient(context.getConnection()).getTableStats(table) : PTableStats.EMPTY_STATS;
    Scan scan = context.getScan();
    // Used to tie all the scans together during logging
    scanId = UUID.randomUUID().toString();
    Map<byte [], NavigableSet<byte []>> familyMap = scan.getFamilyMap();
    boolean keyOnlyFilter = familyMap.isEmpty() && context.getWhereCoditionColumns().isEmpty();
    if (projector.isProjectEmptyKeyValue()) {
        // If nothing projected into scan and we only have one column family, just allow everything
        // to be projected and use a FirstKeyOnlyFilter to skip from row to row. This turns out to
        // be quite a bit faster.
        // Where condition columns also will get added into familyMap
        // When where conditions are present, we can not add FirstKeyOnlyFilter at beginning.
        if (familyMap.isEmpty() && context.getWhereCoditionColumns().isEmpty()
                && table.getColumnFamilies().size() == 1) {
            // Project the one column family. We must project a column family since it's possible
            // that there are other non declared column families that we need to ignore.
            scan.addFamily(table.getColumnFamilies().get(0).getName().getBytes());
        } else {
            byte[] ecf = SchemaUtil.getEmptyColumnFamily(table);
            // Project empty key value unless the column family containing it has
            // been projected in its entirety.
            if (!familyMap.containsKey(ecf) || familyMap.get(ecf) != null) {
                scan.addColumn(ecf, QueryConstants.EMPTY_COLUMN_BYTES);
            }
        }
    } else if (table.getViewType() == ViewType.MAPPED) {
        // Since we don't have the empty key value in MAPPED tables, we must select all CFs in HRS. But only the
        // selected column values are returned back to client
        for (PColumnFamily family : table.getColumnFamilies()) {
            scan.addFamily(family.getName().getBytes());
        }
    }
    // Add FirstKeyOnlyFilter if there are no references to key value columns
    if (keyOnlyFilter) {
        ScanUtil.andFilterAtBeginning(scan, new FirstKeyOnlyFilter());
    }
    
    // TODO adding all CFs here is not correct. It should be done only after ColumnProjectionOptimization.
    if (perScanLimit != null) {
        ScanUtil.andFilterAtEnd(scan, new PageFilter(perScanLimit));
    }

    doColumnProjectionOptimization(context, scan, table, statement);
    
    this.scans = getParallelScans();
    List<KeyRange> splitRanges = Lists.newArrayListWithExpectedSize(scans.size() * ESTIMATED_GUIDEPOSTS_PER_REGION);
    for (List<Scan> scanList : scans) {
        for (Scan aScan : scanList) {
            splitRanges.add(KeyRange.getKeyRange(aScan.getStartRow(), aScan.getStopRow()));
        }
    }
    this.splits = ImmutableList.copyOf(splitRanges);
    // If split detected, this will be more than one, but that's unlikely
    this.allFutures = Lists.newArrayListWithExpectedSize(1);
}
 
Example 5
Source Project: hbase   File: ScannerModel.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param scan the scan specification
 * @throws Exception
 */
public static ScannerModel fromScan(Scan scan) throws Exception {
  ScannerModel model = new ScannerModel();
  model.setStartRow(scan.getStartRow());
  model.setEndRow(scan.getStopRow());
  Map<byte [], NavigableSet<byte []>> families = scan.getFamilyMap();
  if (families != null) {
    for (Map.Entry<byte [], NavigableSet<byte []>> entry : families.entrySet()) {
      if (entry.getValue() != null) {
        for (byte[] qualifier: entry.getValue()) {
          model.addColumn(Bytes.add(entry.getKey(), COLUMN_DIVIDER, qualifier));
        }
      } else {
        model.addColumn(entry.getKey());
      }
    }
  }
  model.setStartTime(scan.getTimeRange().getMin());
  model.setEndTime(scan.getTimeRange().getMax());
  int caching = scan.getCaching();
  if (caching > 0) {
    model.setCaching(caching);
  }
  int batch = scan.getBatch();
  if (batch > 0) {
    model.setBatch(batch);
  }
  int maxVersions = scan.getMaxVersions();
  if (maxVersions > 0) {
    model.setMaxVersions(maxVersions);
  }
  if (scan.getLimit() > 0) {
    model.setLimit(scan.getLimit());
  }
  Filter filter = scan.getFilter();
  if (filter != null) {
    model.setFilter(stringifyFilter(filter));
  }
  // Add the visbility labels if found in the attributes
  Authorizations authorizations = scan.getAuthorizations();
  if (authorizations != null) {
    List<String> labels = authorizations.getLabels();
    for (String label : labels) {
      model.addLabel(label);
    }
  }
  return model;
}
 
Example 6
@VisibleForTesting
public IndexRebuildRegionScanner(final RegionScanner innerScanner, final Region region, final Scan scan,
                          final RegionCoprocessorEnvironment env,
                          UngroupedAggregateRegionObserver ungroupedAggregateRegionObserver) throws IOException {
    super(innerScanner, region, scan, env);
    final Configuration config = env.getConfiguration();
    if (scan.getAttribute(BaseScannerRegionObserver.INDEX_REBUILD_PAGING) == null) {
        partialRebuild = true;
    }
    maxBatchSizeBytes = config.getLong(MUTATE_BATCH_SIZE_BYTES_ATTRIB,
            QueryServicesOptions.DEFAULT_MUTATE_BATCH_SIZE_BYTES);
    mutations = new UngroupedAggregateRegionObserver.MutationList(maxBatchSize);
    blockingMemstoreSize = UngroupedAggregateRegionObserver.getBlockingMemstoreSize(region, config);
    clientVersionBytes = scan.getAttribute(BaseScannerRegionObserver.CLIENT_VERSION);
    indexMetaData = scan.getAttribute(PhoenixIndexCodec.INDEX_PROTO_MD);
    if (indexMetaData == null) {
        useProto = false;
    }
    familyMap = scan.getFamilyMap();
    if (familyMap.isEmpty()) {
        familyMap = null;
    }
    this.ungroupedAggregateRegionObserver = ungroupedAggregateRegionObserver;
    indexRowKey = scan.getAttribute(BaseScannerRegionObserver.INDEX_ROW_KEY);
    if (indexRowKey != null) {
        setReturnCodeForSingleRowRebuild();
        pageSizeInRows = 1;
    }
    byte[] valueBytes = scan.getAttribute(BaseScannerRegionObserver.INDEX_REBUILD_VERIFY_TYPE);
    if (valueBytes != null) {
        verifyType = IndexTool.IndexVerifyType.fromValue(valueBytes);
        if (verifyType != IndexTool.IndexVerifyType.NONE) {
            verify = true;
            viewConstants = IndexUtil.deserializeViewConstantsFromScan(scan);
            byte[] disableLoggingValueBytes =
                scan.getAttribute(BaseScannerRegionObserver.INDEX_REBUILD_DISABLE_LOGGING_VERIFY_TYPE);
            if (disableLoggingValueBytes != null) {
                disableLoggingVerifyType =
                    IndexTool.IndexDisableLoggingType.fromValue(disableLoggingValueBytes);
            }
            verificationOutputRepository =
                new IndexVerificationOutputRepository(indexMaintainer.getIndexTableName()
                    , hTableFactory, disableLoggingVerifyType);
            verificationResult = new IndexToolVerificationResult(scan);
            verificationResultRepository =
                new IndexVerificationResultRepository(indexMaintainer.getIndexTableName(), hTableFactory);
            indexKeyToMutationMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
            dataKeyToMutationMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
            pool = new WaitForCompletionTaskRunner(ThreadPoolManager.getExecutor(
                    new ThreadPoolBuilder("IndexVerify",
                            env.getConfiguration()).setMaxThread(NUM_CONCURRENT_INDEX_VERIFY_THREADS_CONF_KEY,
                            DEFAULT_CONCURRENT_INDEX_VERIFY_THREADS).setCoreTimeout(
                            INDEX_WRITER_KEEP_ALIVE_TIME_CONF_KEY), env));
            nextStartKey = null;
            minTimestamp = scan.getTimeRange().getMin();
        }
    }
}