Exemplo n.º 1
0
 @Test
 public void testInterSegmentAggregationPlanMakerAndRun() {
   PlanMaker instancePlanMaker = new InstancePlanMakerImplV2();
   BrokerRequest brokerRequest = _brokerRequest.deepCopy();
   ExecutorService executorService =
       Executors.newCachedThreadPool(new NamedThreadFactory("test-plan-maker"));
   Plan globalPlan =
       instancePlanMaker.makeInterSegmentPlan(
           makeSegMgrList(_indexSegmentList), brokerRequest, executorService, 150000);
   globalPlan.print();
   globalPlan.execute();
   DataTable instanceResponse = globalPlan.getInstanceResponse();
   LOGGER.debug(Long.toString(instanceResponse.getLong(0, 0)));
   LOGGER.debug(Double.toString(instanceResponse.getDouble(0, 1)));
   LOGGER.debug(Double.toString(instanceResponse.getDouble(0, 2)));
   LOGGER.debug(Double.toString(instanceResponse.getDouble(0, 3)));
   LOGGER.debug(instanceResponse.getObject(0, 4).toString());
   LOGGER.debug(instanceResponse.getObject(0, 5).toString());
   LOGGER.debug(instanceResponse.getObject(0, 6).toString());
   LOGGER.debug("Query time: {}", instanceResponse.getMetadata().get("timeUsedMs"));
   assertEquals(200001L * _indexSegmentList.size(), instanceResponse.getLong(0, 0));
   assertEquals(20000100000.0 * _indexSegmentList.size(), instanceResponse.getDouble(0, 1));
   assertEquals(200000.0, instanceResponse.getDouble(0, 2));
   assertEquals(0.0, instanceResponse.getDouble(0, 3));
   assertEquals(100000.0, Double.parseDouble(instanceResponse.getObject(0, 4).toString()));
   assertEquals(10, ((IntOpenHashSet) instanceResponse.getObject(0, 5)).size());
   assertEquals(100, ((IntOpenHashSet) instanceResponse.getObject(0, 6)).size());
   DefaultReduceService reduceService = new DefaultReduceService();
   Map<ServerInstance, DataTable> instanceResponseMap = new HashMap<ServerInstance, DataTable>();
   instanceResponseMap.put(new ServerInstance("localhost:1111"), instanceResponse);
   BrokerResponseJSON brokerResponse =
       reduceService.reduceOnDataTable(brokerRequest, instanceResponseMap);
   LOGGER.debug(brokerResponse.getAggregationResults().toString());
 }
 public static List<Map<String, Serializable>> transformDataTableToGroupByResult(
     DataTable dataTable) {
   List<Map<String, Serializable>> aggregationGroupByResults =
       new ArrayList<Map<String, Serializable>>();
   for (int i = 0; i < dataTable.getNumberOfRows(); i++) {
     String key = dataTable.getString(i, 0);
     Map<String, Serializable> hashMap = (Map<String, Serializable>) dataTable.getObject(i, 1);
     aggregationGroupByResults.add(hashMap);
   }
   return aggregationGroupByResults;
 }
Exemplo n.º 3
0
 public static Serializable[] extractRowFromDataTable(DataTable dt, int rowId) {
   final Serializable[] row = new Serializable[dt.getDataSchema().size()];
   for (int i = 0; i < dt.getDataSchema().size(); ++i) {
     if (dt.getDataSchema().getColumnType(i).isSingleValue()) {
       switch (dt.getDataSchema().getColumnType(i)) {
         case INT:
           row[i] = dt.getInt(rowId, i);
           break;
         case LONG:
           row[i] = dt.getLong(rowId, i);
           break;
         case DOUBLE:
           row[i] = dt.getDouble(rowId, i);
           break;
         case FLOAT:
           row[i] = dt.getFloat(rowId, i);
           break;
         case STRING:
           row[i] = dt.getString(rowId, i);
           break;
         case SHORT:
           row[i] = dt.getShort(rowId, i);
           break;
         case CHAR:
           row[i] = dt.getChar(rowId, i);
           break;
         case BYTE:
           row[i] = dt.getByte(rowId, i);
           break;
         default:
           row[i] = dt.getObject(rowId, i);
           break;
       }
     } else {
       switch (dt.getDataSchema().getColumnType(i)) {
         case INT_ARRAY:
           row[i] = dt.getIntArray(rowId, i);
           break;
         case LONG_ARRAY:
           row[i] = dt.getLongArray(rowId, i);
           break;
         case DOUBLE_ARRAY:
           row[i] = dt.getDoubleArray(rowId, i);
           break;
         case FLOAT_ARRAY:
           row[i] = dt.getFloatArray(rowId, i);
           break;
         case STRING_ARRAY:
           row[i] = dt.getStringArray(rowId, i);
           break;
         case CHAR_ARRAY:
           row[i] = dt.getCharArray(rowId, i);
           break;
         case BYTE_ARRAY:
           row[i] = dt.getByteArray(rowId, i);
           break;
         default:
           row[i] = dt.getObject(rowId, i);
           break;
       }
     }
   }
   return row;
 }