public SingleRowDeleteMutationPlan(QueryPlan dataPlan, PhoenixConnection connection, int maxSize, int maxSizeBytes) { this.dataPlan = dataPlan; this.connection = connection; this.maxSize = maxSize; this.context = dataPlan.getContext(); this.maxSizeBytes = maxSizeBytes; }
public ServerSelectDeleteMutationPlan(QueryPlan dataPlan, PhoenixConnection connection, QueryPlan aggPlan, RowProjector projector, int maxSize, int maxSizeBytes) { this.context = dataPlan.getContext(); this.dataPlan = dataPlan; this.connection = connection; this.aggPlan = aggPlan; this.projector = projector; this.maxSize = maxSize; this.maxSizeBytes = maxSizeBytes; }
private synchronized void openCursor(Connection conn) throws SQLException { if(isOpen){ return; } this.scan = this.queryPlan.getContext().getScan(); isReversed=OrderBy.REV_ROW_KEY_ORDER_BY.equals(this.queryPlan.getOrderBy()); isOpen = true; }
private int getScannerCacheSize() { try { return plan.getContext().getStatement().getFetchSize(); } catch (Throwable e) { Throwables.propagate(e); } return -1; // unreachable }
public ServerCache createServerCache(byte[] cacheId, QueryPlan delegate) throws SQLException, IOException { PTable cacheUsingTable = delegate.getTableRef().getTable(); ConnectionQueryServices services = delegate.getContext().getConnection().getQueryServices(); List<HRegionLocation> locations = services.getAllTableRegions( cacheUsingTable.getPhysicalName().getBytes()); int nRegions = locations.size(); Set<HRegionLocation> servers = new HashSet<>(nRegions); cacheUsingTableMap.put(Bytes.mapKey(cacheId), cacheUsingTable); return new ServerCache(cacheId, servers, new ImmutableBytesWritable( new byte[]{}), services, false); }
@Override public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException { StatementContext context = delegate.getContext(); if (resultIterator == null) { context.getOverallQueryMetrics().startQuery(); resultIterator = new CursorResultIterator(LookAheadResultIterator.wrap(delegate.iterator(scanGrouper, scan)),cursorName); } return resultIterator; }
private Scan projectQuery(String query) throws SQLException { QueryPlan plan = getQueryPlan(query, Collections.emptyList()); plan.iterator(); // Forces projection return plan.getContext().getScan(); }
@Test public void testMultiCFProjection() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); String ddl = "CREATE TABLE multiCF (k integer primary key, a.a varchar, b.b varchar)"; conn.createStatement().execute(ddl); String query = "SELECT COUNT(*) FROM multiCF"; QueryPlan plan = getQueryPlan(query,Collections.emptyList()); plan.iterator(); Scan scan = plan.getContext().getScan(); assertTrue(scan.getFilter() instanceof FirstKeyOnlyFilter); assertEquals(1, scan.getFamilyMap().size()); }
@Test public void testDegenerateRowKeyFilter() throws SQLException { String keyPrefix = "foobar"; String query = "select * from atable where substr(entity_id,1,3)=?"; List<Object> binds = Arrays.<Object>asList(keyPrefix); PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class); PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query); bindParams(pstmt, binds); QueryPlan plan = pstmt.optimizeQuery(); // Degenerate b/c "foobar" is more than 3 characters assertDegenerate(plan.getContext()); }
private static Filter compileStatement(String query) throws SQLException { PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class); PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query); QueryPlan plan = pstmt.compileQuery(); return plan.getContext().getScan().getFilter(); }
private static StatementContext compileStatement(String query, List<Object> binds, Integer limit) throws SQLException { PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class); PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query); assertRoundtrip(query); TestUtil.bindParams(pstmt, binds); QueryPlan plan = pstmt.compileQuery(); assertEquals(limit, plan.getLimit()); return plan.getContext(); }
@Test public void testSelectForceSkipScan() throws Exception { String id = "000000000000001"; // A where clause without the first column usually compiles into a range scan. String query = "SELECT /*+ SKIP_SCAN */ * FROM atable WHERE entity_id='" + id + "'"; Scan scan = compileStatement(query).getContext().getScan(); assertTrue("The first filter should be SkipScanFilter.", usingSkipScan(scan)); }
@Test public void testSelectForceRangeScan() throws Exception { String query = "SELECT /*+ RANGE_SCAN */ * FROM atable WHERE organization_id in (" + "'000000000000001', '000000000000002', '000000000000003', '000000000000004')"; Scan scan = compileStatement(query).getContext().getScan(); // Verify that it is not using SkipScanFilter. assertFalse("The first filter should not be SkipScanFilter.", usingSkipScan(scan)); }
private static Expressions compileStatement(String query, List<Object> binds) throws SQLException { PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class); PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query); TestUtil.bindParams(pstmt, binds); QueryPlan plan = pstmt.compileQuery(); assertTrue(plan instanceof AggregatePlan); Filter filter = plan.getContext().getScan().getFilter(); assertTrue(filter == null || filter instanceof BooleanExpressionFilter); BooleanExpressionFilter boolFilter = (BooleanExpressionFilter)filter; AggregatePlan aggPlan = (AggregatePlan)plan; return new Expressions(boolFilter == null ? null : boolFilter.getExpression(), aggPlan.getHaving()); }
@Test public void testBoundLimit() throws SQLException { String tenantId = "000000000000001"; String query = "select * from atable where organization_id='" + tenantId + "' limit ?"; List<Object> binds = Arrays.<Object>asList(5); QueryPlan plan = compileStatement(query, binds); Scan scan = plan.getContext().getScan(); assertNull(scan.getFilter()); assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow()); assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow()); assertEquals(plan.getLimit(),Integer.valueOf(5)); }
@Test public void testLimit() throws SQLException { String tenantId = "000000000000001"; String query = "select * from atable where organization_id='" + tenantId + "' limit 5"; List<Object> binds = Collections.emptyList(); QueryPlan plan = compileStatement(query, binds); Scan scan = plan.getContext().getScan(); assertNull(scan.getFilter()); assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow()); assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow()); assertEquals(plan.getLimit(),Integer.valueOf(5)); }
@Test public void testCollapseFunctionToNull() throws SQLException { String query = "select * from atable where substr(entity_id,null) = 'foo'"; PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class); PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query); QueryPlan plan = pstmt.optimizeQuery(); Scan scan = plan.getContext().getScan(); Filter filter = scan.getFilter(); assertNull(filter); assertArrayEquals(scan.getStartRow(),KeyRange.EMPTY_RANGE.getLowerRange()); assertArrayEquals(scan.getStopRow(),KeyRange.EMPTY_RANGE.getUpperRange()); }
private static void assertQualifierRangesNotPresent(ResultSet rs) throws SQLException { Scan scan = rs.unwrap(PhoenixResultSet.class).getStatement().getQueryPlan().getContext().getScan(); assertNull(scan.getAttribute(MIN_QUALIFIER)); assertNull(scan.getAttribute(MAX_QUALIFIER)); } }
@Test public void testNoLimit() throws SQLException { String tenantId = "000000000000001"; String query = "select * from atable where organization_id='" + tenantId + "'"; List<Object> binds = Collections.emptyList(); QueryPlan plan = compileStatement(query, binds); Scan scan = plan.getContext().getScan(); assertNull(scan.getFilter()); assertNull(plan.getLimit()); assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow()); assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow()); }
private static void assertQualifierRanges(ResultSet rs, int minQualifier, int maxQualifier) throws SQLException { Scan scan = rs.unwrap(PhoenixResultSet.class).getStatement().getQueryPlan().getContext().getScan(); assertNotNull(scan.getAttribute(MIN_QUALIFIER)); assertNotNull(scan.getAttribute(MAX_QUALIFIER)); assertEquals(minQualifier, Bytes.toInt(scan.getAttribute(MIN_QUALIFIER))); assertEquals(maxQualifier, Bytes.toInt(scan.getAttribute(MAX_QUALIFIER))); }