Ejemplo n.º 1
0
 public static Object getAllValue(FieldSpec spec) {
   Object allValue;
   switch (spec.getDataType()) {
     case INT:
       allValue = V1Constants.STARTREE_ALL_NUMBER.intValue();
       break;
     case LONG:
       allValue = V1Constants.STARTREE_ALL_NUMBER.longValue();
       break;
     case FLOAT:
       allValue = V1Constants.STARTREE_ALL_NUMBER.floatValue();
       break;
     case DOUBLE:
       allValue = V1Constants.STARTREE_ALL_NUMBER.doubleValue();
       break;
     case STRING:
     case BOOLEAN:
       allValue = V1Constants.STARTREE_ALL;
       break;
     default:
       throw new UnsupportedOperationException(
           "unsupported data type : "
               + spec.getDataType()
               + " : "
               + " for column : "
               + spec.getName());
   }
   return allValue;
 }
Ejemplo n.º 2
0
  /** Converts a raw row into its (possibly partial) dimension and complete metric values */
  private StarTreeTableRow extractValues(GenericRow row) {
    List<Integer> dimensions = new ArrayList<Integer>();
    for (String dimensionName : schema.getDimensionNames()) {
      Integer valueId;
      if (schema.getFieldSpecFor(dimensionName).isSingleValueField()
          && !starTreeIndexSpec.getExcludedDimensions().contains(dimensionName)) {
        Object value = row.getValue(dimensionName);
        valueId = dictionaryCreatorMap.get(dimensionName).indexOfSV(value);
      } else {
        // Multi-value fields are not supported - always ALL
        valueId = V1Constants.STARTREE_ALL_NUMBER.intValue();
      }

      dimensions.add(valueId);
    }

    List<Number> metrics = new ArrayList<Number>(schema.getMetricNames().size());
    for (MetricFieldSpec metricFieldSpec : schema.getMetricFieldSpecs()) {
      Object value = row.getValue(metricFieldSpec.getName());
      switch (metricFieldSpec.getDataType()) {
        case INT:
          metrics.add((Integer) value);
          break;
        case LONG:
          metrics.add((Long) value);
          break;
        case DOUBLE:
          metrics.add((Double) value);
          break;
        case FLOAT:
          metrics.add((Float) value);
          break;
        default:
          throw new IllegalStateException("Unsupported data type " + metricFieldSpec.getDataType());
      }
    }

    return new StarTreeTableRow(dimensions, metrics);
  }