Search in sources :

Example 46 with KeyRange

use of org.apache.phoenix.query.KeyRange in project phoenix by apache.

the class ScanRanges method getBoundPkSpan.

/**
     * Finds the total number of row keys spanned by this ranges / slotSpan pair.
     * This accounts for slots in the ranges that may span more than on row key.
     * @param ranges  the KeyRange slots paired with this slotSpan. corresponds to {@link ScanRanges#ranges}
     * @param slotSpan  the extra span per skip scan slot. corresponds to {@link ScanRanges#slotSpan}
     * @return  the total number of row keys spanned yb this ranges / slotSpan pair.
     */
private static int getBoundPkSpan(List<List<KeyRange>> ranges, int[] slotSpan) {
    int count = 0;
    boolean hasUnbound = false;
    int nRanges = ranges.size();
    for (int i = 0; i < nRanges && !hasUnbound; i++) {
        List<KeyRange> orRanges = ranges.get(i);
        for (KeyRange range : orRanges) {
            if (range == KeyRange.EVERYTHING_RANGE) {
                return count;
            }
            if (range.isUnbound()) {
                hasUnbound = true;
            }
        }
        count += slotSpan[i] + 1;
    }
    return count;
}
Also used : KeyRange(org.apache.phoenix.query.KeyRange)

Example 47 with KeyRange

use of org.apache.phoenix.query.KeyRange in project phoenix by apache.

the class ScanRanges method getRowTimestampColumnRange.

private static TimeRange getRowTimestampColumnRange(List<List<KeyRange>> ranges, RowKeySchema schema, int rowTimestampColPos) {
    try {
        if (rowTimestampColPos != -1) {
            if (ranges != null && ranges.size() > rowTimestampColPos) {
                List<KeyRange> rowTimestampColRange = ranges.get(rowTimestampColPos);
                List<KeyRange> sortedRange = new ArrayList<>(rowTimestampColRange);
                Collections.sort(sortedRange, KeyRange.COMPARATOR);
                //ranges.set(rowTimestampColPos, sortedRange); //TODO: do I really need to do this?
                Field f = schema.getField(rowTimestampColPos);
                SortOrder order = f.getSortOrder();
                KeyRange lowestRange = rowTimestampColRange.get(0);
                KeyRange highestRange = rowTimestampColRange.get(rowTimestampColRange.size() - 1);
                if (order == SortOrder.DESC) {
                    return getDescTimeRange(lowestRange, highestRange, f);
                }
                return getAscTimeRange(lowestRange, highestRange, f);
            }
        }
    } catch (IOException e) {
        Throwables.propagate(e);
    }
    return null;
}
Also used : Field(org.apache.phoenix.schema.ValueSchema.Field) KeyRange(org.apache.phoenix.query.KeyRange) ArrayList(java.util.ArrayList) SortOrder(org.apache.phoenix.schema.SortOrder) IOException(java.io.IOException)

Example 48 with KeyRange

use of org.apache.phoenix.query.KeyRange in project phoenix by apache.

the class PhoenixInputFormat method getSplits.

@Override
public List<InputSplit> getSplits(JobContext context) throws IOException, InterruptedException {
    final Configuration configuration = context.getConfiguration();
    final QueryPlan queryPlan = getQueryPlan(context, configuration);
    final List<KeyRange> allSplits = queryPlan.getSplits();
    final List<InputSplit> splits = generateSplits(queryPlan, allSplits, configuration);
    return splits;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) KeyRange(org.apache.phoenix.query.KeyRange) QueryPlan(org.apache.phoenix.compile.QueryPlan) InputSplit(org.apache.hadoop.mapreduce.InputSplit)

Example 49 with KeyRange

use of org.apache.phoenix.query.KeyRange in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testCeilDecimalExpressionKeyRangeSimple.

@Test
public void testCeilDecimalExpressionKeyRangeSimple() throws Exception {
    ScalarFunction ceilDecimalExpression = (ScalarFunction) CeilDecimalExpression.create(DUMMY_DECIMAL, 3);
    byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.238"));
    byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.237"));
    KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, false, upperBound, true);
    KeyPart keyPart = ceilDecimalExpression.newKeyPart(null);
    assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), PDecimal.INSTANCE)));
}
Also used : ScalarFunction(org.apache.phoenix.expression.function.ScalarFunction) KeyRange(org.apache.phoenix.query.KeyRange) KeyPart(org.apache.phoenix.compile.KeyPart) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 50 with KeyRange

use of org.apache.phoenix.query.KeyRange in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testRoundDecimalExpressionKeyRangeSimple.

// KeyRange explicit simple / sanity tests
@Test
public void testRoundDecimalExpressionKeyRangeSimple() throws Exception {
    ScalarFunction roundDecimalExpression = (ScalarFunction) RoundDecimalExpression.create(DUMMY_DECIMAL, 3);
    byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.2385"));
    byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.2375"));
    KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, upperBound);
    KeyPart keyPart = roundDecimalExpression.newKeyPart(null);
    assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), PDecimal.INSTANCE)));
}
Also used : ScalarFunction(org.apache.phoenix.expression.function.ScalarFunction) KeyRange(org.apache.phoenix.query.KeyRange) KeyPart(org.apache.phoenix.compile.KeyPart) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

KeyRange (org.apache.phoenix.query.KeyRange)51 Test (org.junit.Test)23 Connection (java.sql.Connection)16 ResultSet (java.sql.ResultSet)14 PreparedStatement (java.sql.PreparedStatement)9 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Properties (java.util.Properties)7 Scan (org.apache.hadoop.hbase.client.Scan)7 ScanRanges (org.apache.phoenix.compile.ScanRanges)6 BigDecimal (java.math.BigDecimal)5 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)5 KeyPart (org.apache.phoenix.compile.KeyPart)4 QueryPlan (org.apache.phoenix.compile.QueryPlan)4 PhoenixStatement (org.apache.phoenix.jdbc.PhoenixStatement)4 Field (org.apache.phoenix.schema.ValueSchema.Field)4 KeyValue (org.apache.hadoop.hbase.KeyValue)3 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)3 IOException (java.io.IOException)2 Statement (java.sql.Statement)2