package io.druid.data.input;

import com.google.common.collect.Maps;
import com.metamx.common.ISE;

import java.util.List;
import java.util.TreeMap;

/**
 */
public class Rows
{
  public static InputRow toCaseInsensitiveInputRow(final Row row, final List<String> dimensions)
  {
    if (row instanceof MapBasedRow) {
      MapBasedRow mapBasedRow = (MapBasedRow) row;

      TreeMap<String, Object> caseInsensitiveMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
      caseInsensitiveMap.putAll(mapBasedRow.getEvent());
      return new MapBasedInputRow(
          mapBasedRow.getTimestampFromEpoch(),
          dimensions,
          caseInsensitiveMap
      );
    }
    throw new ISE("Can only convert MapBasedRow objects because we are ghetto like that.");
  }
}

@@ -23,16 +23,117 @@
 input;%0A%0A
+import com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableSortedSet;%0A
 import c
@@ -163,16 +163,16 @@
 t.Maps;%0A
-
 import c
@@ -213,24 +213,68 @@
 .util.List;%0A
+import java.util.Map;%0Aimport java.util.Set;%0A
 import java.
@@ -811,16 +811,16 @@
 ;%0A    %7D%0A
-
     thro
@@ -906,11 +906,615 @@
 .%22);%0A  %7D
+%0A%0A  /**%0A   * @param timeStamp rollup up timestamp to be used to create group key%0A   * @param inputRow input row%0A   * @return groupKey for the given input row%0A   */%0A  public static List%3CObject%3E toGroupKey(long timeStamp, InputRow inputRow)%0A  %7B%0A    final Map%3CString, Set%3CString%3E%3E dims = Maps.newTreeMap();%0A    for (final String dim : inputRow.getDimensions()) %7B%0A      final Set%3CString%3E dimValues = ImmutableSortedSet.copyOf(inputRow.getDimension(dim));%0A      if (dimValues.size() %3E 0) %7B%0A        dims.put(dim, dimValues);%0A      %7D%0A    %7D%0A    return ImmutableList.of(%0A        timeStamp,%0A        dims%0A    );%0A  %7D
 %0A%7D%0A

abstract out utility method