Java Code Examples for org.apache.phoenix.schema.PTable#getColumnFamilies()

The following examples show how to use org.apache.phoenix.schema.PTable#getColumnFamilies() . 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: ConnectionQueryServicesImpl.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private HashSet<String> existingColumnFamilies(PTable table) {
    List<PColumnFamily> cfs = table.getColumnFamilies();
    HashSet<String> cfNames = new HashSet<>(cfs.size());
    for (PColumnFamily cf : table.getColumnFamilies()) {
        cfNames.add(cf.getName().getString());
    }
    return cfNames;
}
 
Example 2
Source File: ProjectionCompiler.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void projectAllColumnFamilies(PTable table, Scan scan) {
    // Will project all known/declared column families
    scan.getFamilyMap().clear();
    for (PColumnFamily family : table.getColumnFamilies()) {
        scan.addFamily(family.getName().getBytes());
    }
}
 
Example 3
Source File: GuidePostsCacheWrapper.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public void invalidateAll(PTable table) {
    Preconditions.checkNotNull(table);
    byte[] physicalName = table.getPhysicalName().getBytes();
    List<PColumnFamily> families = table.getColumnFamilies();
    if (families.isEmpty()) {
        invalidate(new GuidePostsKey(physicalName, SchemaUtil.getEmptyColumnFamily(table)));
    } else {
        for (PColumnFamily family : families) {
            invalidate(new GuidePostsKey(physicalName, family.getName().getBytes()));
        }
    }
}
 
Example 4
Source File: ProjectionCompiler.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void projectAllColumnFamilies(PTable table, Scan scan) {
    // Will project all known/declared column families
    scan.getFamilyMap().clear();
    for (PColumnFamily family : table.getColumnFamilies()) {
        scan.addFamily(family.getName().getBytes());
    }
}
 
Example 5
Source File: BaseResultIterators.java    From phoenix with 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 6
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static byte[] getEmptyColumnFamily(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
}
 
Example 7
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static ImmutableBytesPtr getEmptyColumnFamilyPtr(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
            .getName().getBytesPtr();
}
 
Example 8
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static byte[] getEmptyColumnFamily(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES) : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
}
 
Example 9
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static String getEmptyColumnFamilyAsString(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY : QueryConstants.DEFAULT_COLUMN_FAMILY) : table.getDefaultFamilyName().getString() : families.get(0).getName().getString();
}
 
Example 10
Source File: SchemaUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static ImmutableBytesPtr getEmptyColumnFamilyPtr(PTable table) {
    List<PColumnFamily> families = table.getColumnFamilies();
    return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES_PTR : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR) : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
            .getName().getBytesPtr();
}
 
Example 11
Source File: PArrayDataTypeEncoder.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * @param colValueMap map from column to value
 * @return estimated encoded size
 */
public static int getEstimatedByteSize(PTable table, int rowLength,
        Map<PColumn, byte[]> colValueMap) {
    // iterate over column familiies
    int rowSize = 0;
    for (PColumnFamily family : table.getColumnFamilies()) {
        Collection<PColumn> columns = family.getColumns();
        // we add a non null value to the start so that we can represent absent values in the array with negative offsets
        int numColumns = columns.size() + 1;
        int cellSize = 1;
        int nulls = 0;
        int maxOffset = 0;
        // iterate over columns
        for (PColumn column : columns) {
            if (colValueMap.containsKey(column)) {
                byte[] colValue = colValueMap.get(column);
                // the column value is null
                if (colValue == null || colValue.length == 0) {
                    ++nulls;
                    maxOffset = cellSize;
                } else {
                    // count the bytes written to serialize nulls
                    if (nulls > 0) {
                        cellSize += (1 + Math.ceil(nulls / 255));
                        nulls = 0;
                    }
                    maxOffset = cellSize;
                    cellSize += colValue.length;
                }
            }
            // the column value is absent
            else {
                ++nulls;
                maxOffset = cellSize;
            }
        }
        // count the bytes used for the offset array
        cellSize +=
                PArrayDataType.useShortForOffsetArray(maxOffset,
                    PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION)
                            ? numColumns * Bytes.SIZEOF_SHORT
                            : numColumns * Bytes.SIZEOF_INT;
        cellSize += 4;
        // count the bytes used for header information
        cellSize += 5;
        // add the size of the single cell containing all column values
        rowSize +=
                KeyValue.getKeyValueDataStructureSize(rowLength,
                    family.getName().getBytes().length,
                    QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES.length, cellSize);
    }
    return rowSize;
}