@Override default int compareTo(QueryCost queryCost) { return (new Double(this.getEstimatedResourceUsage())) .compareTo(queryCost.getEstimatedResourceUsage()); }
@Test public void testCompareTo() throws Exception { assertEquals(cost1.compareTo(cost2), -1); assertEquals(cost2.compareTo(cost1), 1); assertEquals(cost1.compareTo(cost11), 0); assertEquals(scost1.compareTo(scost0), 1); assertEquals(scost0.compareTo(scost1), -1); assertEquals(scost2.compareTo(scost0), 1); }
public QueryCostTO build() { Long estimatedExecTimeMillis = null; Double estimatedResourceUsage = null; try { estimatedExecTimeMillis = cost.getEstimatedExecTimeMillis(); } catch (UnsupportedOperationException e) { log.debug("estimated exec time not supported for {}", cost.getClass().getCanonicalName()); } try { estimatedResourceUsage = cost.getEstimatedResourceUsage(); } catch (UnsupportedOperationException e) { log.debug("estimated resource usage not supported for {}", cost.getClass().getCanonicalName()); } return new QueryCostTO(estimatedExecTimeMillis, estimatedResourceUsage, cost.getQueryCostType()); } }
@Test(expectedExceptions = {UnsupportedOperationException.class}) public void testEstimateNativeQuery() throws Exception { createTestTable("test_estimate"); SessionState.setCurrentSessionState(ss); QueryCost cost = driver.estimate(createExplainContext("SELECT ID FROM test_estimate", queryConf)); assertEquals(cost.getEstimatedResourceUsage(), Double.MAX_VALUE); cost.getEstimatedExecTimeMillis(); }
@Test(expectedExceptions = {UnsupportedOperationException.class}) public void testGetEstimatedExecTimeMillis() throws Exception { cost1.getEstimatedExecTimeMillis(); }
@Override public QueryCost calculateCost(final AbstractQueryContext queryContext, LensDriver driver) throws LensException { Double cost = getTotalPartitionCost(queryContext, driver); QueryCost queryCost = cost == null ? null : new FactPartitionBasedQueryCost(cost); if (queryCost != null) { queryCost.setQueryCostType(queryCostTypeDecider.decideCostType(queryCost)); } return queryCost; }
@Test public void testGetQueryCostType() throws Exception { assertEquals(cost1.getQueryCostType(), QueryCostType.HIGH); assertEquals(cost2.getQueryCostType(), QueryCostType.HIGH); assertEquals(cost0.getQueryCostType(), QueryCostType.LOW); assertEquals(scost0.getQueryCostType(), QueryCostType.VERY_LOW); }
@Test public void testAdd() throws Exception { assertEquals(cost1.add(cost2), new FactPartitionBasedQueryCost(0.5)); }
@Test(expectedExceptions = {UnsupportedOperationException.class}) public void testEstimateOlapQuery() throws Exception { SessionState.setCurrentSessionState(ss); ExplainQueryContext ctx = createExplainContext("cube SELECT ID FROM test_cube", queryConf); ctx.setOlapQuery(true); ctx.getDriverContext().setDriverRewriterPlan(driver, new DriverQueryPlan() { @Override public String getPlan() { return null; } @Override public QueryCost getCost() { return null; } @Override public Map<String, Set<?>> getPartitions() { return Maps.newHashMap(); } }); QueryCost cost = driver.estimate(ctx); assertEquals(cost.getEstimatedResourceUsage(), 0.0); cost.getEstimatedExecTimeMillis(); }
@BeforeTest public void beforeTest() throws LensException { cost0.setQueryCostType(costRangeQueryTypeDecider.decideCostType(cost0)); cost1.setQueryCostType(costRangeQueryTypeDecider.decideCostType(cost1)); cost11.setQueryCostType(costRangeQueryTypeDecider.decideCostType(cost11)); cost2.setQueryCostType(costRangeQueryTypeDecider.decideCostType(cost2)); scost0.setQueryCostType(costRangeQueryTypeDecider.decideCostType(scost0)); scost1.setQueryCostType(costRangeQueryTypeDecider.decideCostType(scost1)); scost2.setQueryCostType(costRangeQueryTypeDecider.decideCostType(scost2)); } @Test(expectedExceptions = {IllegalArgumentException.class})
@Override public Priority decidePriority(@NonNull final QueryCost cost) throws LensException { Priority p = costToPriorityRangeMap.get(cost.getEstimatedResourceUsage()); log.info("cost was: {}, decided priority: {}", cost, p); return p; } }
public QueryCostTO build() { Long estimatedExecTimeMillis = null; Double estimatedResourceUsage = null; try { estimatedExecTimeMillis = cost.getEstimatedExecTimeMillis(); } catch (UnsupportedOperationException e) { log.debug("estimated exec time not supported for {}", cost.getClass().getCanonicalName()); } try { estimatedResourceUsage = cost.getEstimatedResourceUsage(); } catch (UnsupportedOperationException e) { log.debug("estimated resource usage not supported for {}", cost.getClass().getCanonicalName()); } return new QueryCostTO(estimatedExecTimeMillis, estimatedResourceUsage, cost.getQueryCostType()); } }
@Override public int compare(LensDriver d1, LensDriver d2) { final QueryCost c1 = ctx.getDriverQueryCost(d1); final QueryCost c2 = ctx.getDriverQueryCost(d2); return c1.compareTo(c2); } });
@Override public void init(LensDriver lensDriver) throws LensException { QueryCostTypeDecider queryCostTypeDecider = new RangeBasedQueryCostTypeDecider( lensDriver.getConf().get(DRIVER_COST_TYPE_RANGES, DRIVER_QUERY_COST_TYPE_DEFAULT_RANGES)); this.queryCost = new StaticQueryCost(lensDriver.getConf().getDouble(DRIVER_QUERY_COST, DEFAULT_DRIVER_QUERY_COST)); this.queryCost.setQueryCostType(queryCostTypeDecider.decideCostType(this.queryCost)); }
@Override public QueryCostType decideCostType(@NonNull final QueryCost cost) throws LensException { QueryCostType q = queryCostTypeRangeMap.get(cost.getEstimatedResourceUsage()); log.info("cost was: {}, decided querytype: {}", cost, q); return q; } }
@Override public int compare(LensDriver d1, LensDriver d2) { final QueryCost c1 = ctx.getDriverQueryCost(d1); final QueryCost c2 = ctx.getDriverQueryCost(d2); return c1.compareTo(c2); } });
@Override public Priority decidePriority(@NonNull final QueryCost cost) throws LensException { Priority p = costToPriorityRangeMap.get(cost.getEstimatedResourceUsage()); log.info("cost was: {}, decided priority: {}", cost, p); return p; } }
@Override public int compare(final QueryContext o1, final QueryContext o2) { return o1.getSelectedDriverQueryCost().compareTo(o2.getSelectedDriverQueryCost()); } }
@Test public void testGetEstimatedResourceUsage() throws Exception { assertEquals(cost1.getEstimatedResourceUsage(), 0.2); }
@Override public int compare(LensDriver d1, LensDriver d2) { final QueryCost c1 = ctx.getDriverQueryCost(d1); final QueryCost c2 = ctx.getDriverQueryCost(d2); return c1.compareTo(c2); } });