// Copyright 2015 Cloudera 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 com.cloudera.impala.planner;

import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.kududb.ColumnSchema;
import org.kududb.Schema;
import org.kududb.Type;
import org.kududb.client.CreateTableResponse;
import org.kududb.client.Insert;
import org.kududb.client.KuduClient;
import org.kududb.client.KuduSession;
import org.kududb.client.KuduTable;

import com.cloudera.impala.common.RuntimeEnv;
import com.google.common.collect.Lists;
import com.google.common.net.HostAndPort;

/**
 * This class contains all plan generation related tests with Kudu as a storage backend.
 */
public class KuduPlannerTest extends PlannerTestBase {


  @BeforeClass
  public static void setUp() throws Exception {
    // Use 8 cores for resource estimation.
    RuntimeEnv.INSTANCE.setNumCores(8);
    // Set test env to control the explain level.
    RuntimeEnv.INSTANCE.setTestEnv(true);

    KuduClient c = new KuduClient(Lists.newArrayList(
        HostAndPort.fromParts("127.0.0.1", 7051)));

    // Create the Schema
    List<org.kududb.ColumnSchema> cols = Lists.newArrayList(
        new ColumnSchema.ColumnSchemaBuilder("str_col", Type.STRING).key(true).build(),
        new ColumnSchema.ColumnSchemaBuilder("match_like_col", Type.STRING).build(),
        new ColumnSchema.ColumnSchemaBuilder("no_match_like_col", Type.STRING).build(),
        new ColumnSchema.ColumnSchemaBuilder("match_regex_col", Type.STRING).build(),
        new ColumnSchema.ColumnSchemaBuilder("no_match_regex_col", Type.STRING).build());


    if (c.tableExists("liketbl")) {
      c.deleteTable("liketbl");
    }

    // Create the table
    CreateTableResponse res = c.createTable("liketbl", new Schema(cols));

    KuduTable table = c.openTable("liketbl");
    KuduSession session = c.newSession();
    // Load data
    for (int i = 0; i < 1000; ++i) {
      Insert insert = table.newInsert();
      insert.addString("str_col", String.valueOf(i));
      insert.addString("match_like_col", String.valueOf(i));
      insert.addString("no_match_like_col", String.valueOf(i));
      insert.addString("match_regex_col", String.valueOf(i));
      insert.addString("no_match_regex_col", String.valueOf(i));
      session.apply(insert);
    }
    session.flush();
  }

  @Test
  public void testKudu() {
    runPlannerTestFile("kudu");
  }

}

@@ -629,2228 +629,176 @@
 ort 
-java.util.List;%0A%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport org.kududb.ColumnSchema;%0Aimport org.kududb.Schema;%0Aimport org.kududb.Type;%0Aimport org.kududb.client.CreateTableResponse;%0Aimport org.kududb.client.Insert;%0Aimport org.kududb.client.KuduClient;%0Aimport org.kududb.client.KuduSession;%0Aimport org.kududb.client.KuduTable;%0A%0Aimport com.cloudera.impala.common.RuntimeEnv;%0Aimport com.google.common.collect.Lists;%0Aimport com.google.common.net.HostAndPort;%0A%0A/**%0A * This class contains all plan generation related tests with Kudu as a storage backend.%0A */%0Apublic class KuduPlannerTest extends PlannerTestBase %7B%0A%0A%0A  @BeforeClass%0A  public static void setUp() throws Exception %7B%0A    // Use 8 cores for resource estimation.%0A    RuntimeEnv.INSTANCE.setNumCores(8);%0A    // Set test env to control the explain level.%0A    RuntimeEnv.INSTANCE.setTestEnv(true);%0A%0A    KuduClient c = new KuduClient(Lists.newArrayList(%0A        HostAndPort.fromParts(%22127.0.0.1%22, 7051)));%0A%0A    // Create the Schema%0A    List%3Corg.kududb.ColumnSchema%3E cols = Lists.newArrayList(%0A        new ColumnSchema.ColumnSchemaBuilder(%22str_col%22, Type.STRING).key(true).build(),%0A        new ColumnSchema.ColumnSchemaBuilder(%22match_like_col%22, Type.STRING).build(),%0A        new ColumnSchema.ColumnSchemaBuilder(%22no_match_like_col%22, Type.STRING).build(),%0A        new ColumnSchema.ColumnSchemaBuilder(%22match_regex_col%22, Type.STRING).build(),%0A        new ColumnSchema.ColumnSchemaBuilder(%22no_match_regex_col%22, Type.STRING).build());%0A%0A%0A    if (c.tableExists(%22liketbl%22)) %7B%0A      c.deleteTable(%22liketbl%22);%0A    %7D%0A%0A    // Create the table%0A    CreateTableResponse res = c.createTable(%22liketbl%22, new Schema(cols));%0A%0A    KuduTable table = c.openTable(%22liketbl%22);%0A    KuduSession session = c.newSession();%0A    // Load data%0A    for (int i = 0; i %3C 1000; ++i) %7B%0A      Insert insert = table.newInsert();%0A      insert.addString(%22str_col%22, String.valueOf(i));%0A      insert.addString(%22match_like_col%22, String.valueOf(i));%0A      insert.addString(%22no_match_like_col%22, String.valueOf(i));%0A      insert.addString(%22match_regex_col%22, String.valueOf(i));%0A      insert.addString(%22no_match_regex_col%22, String.valueOf(i));%0A      session.apply(insert);%0A    %7D%0A    session.flush();%0A  %7D
+org.junit.Test;%0A%0A/**%0A * This class contains all plan generation related tests with Kudu as a storage backend.%0A */%0Apublic class KuduPlannerTest extends PlannerTestBase %7B
 %0A%0A  

Stop creating test tables in KuduPlannerTest