Java tutorial
/* * Druid - a distributed column store. * Copyright 2012 - 2015 Metamarkets Group Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package io.druid.query.groupby; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.metamx.common.guava.Sequence; import com.metamx.common.guava.Sequences; import io.druid.data.input.MapBasedRow; import io.druid.data.input.Row; import io.druid.query.FinalizeResultsQueryRunner; import io.druid.query.QueryRunner; import io.druid.query.QueryRunnerFactory; import io.druid.query.QueryToolChest; import org.joda.time.DateTime; import java.util.Map; /** */ public class GroupByQueryRunnerTestHelper { public static Iterable<Row> runQuery(QueryRunnerFactory factory, QueryRunner runner, GroupByQuery query) { QueryToolChest toolChest = factory.getToolchest(); QueryRunner theRunner = new FinalizeResultsQueryRunner<>( toolChest.mergeResults(toolChest.preMergeQueryDecoration(runner)), toolChest); Sequence<Row> queryResult = theRunner.run(query, Maps.newHashMap()); return Sequences.toList(queryResult, Lists.<Row>newArrayList()); } public static Row createExpectedRow(final String timestamp, Object... vals) { return createExpectedRow(new DateTime(timestamp), vals); } public static Row createExpectedRow(final DateTime timestamp, Object... vals) { Preconditions.checkArgument(vals.length % 2 == 0); Map<String, Object> theVals = Maps.newHashMap(); for (int i = 0; i < vals.length; i += 2) { theVals.put(vals[i].toString(), vals[i + 1]); } DateTime ts = new DateTime(timestamp); return new MapBasedRow(ts, theVals); } }