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;
}
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;
}
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;
}
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)));
}
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)));
}
Aggregations