예제 #1
0
 @Test
 public void testTimeZoneSessionVars2() throws Exception {
   tajoCli.executeScript("SET TIME ZONE 'GMT+2'");
   tajoCli.executeMetaCommand("\\set");
   String output = new String(out.toByteArray());
   assertTrue(output.contains("'TIMEZONE'='GMT+2'"));
 }
예제 #2
0
  @Test
  public void testParseConf() throws Exception {
    String[] args =
        new String[] {
          "--conf",
          "tajo.cli.print.pause=false",
          "--conf",
          "tajo.executor.join.inner.in-memory-table-num=256"
        };

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(TajoCli.options, args);
    String[] confValues = cmd.getOptionValues("conf");

    assertNotNull(confValues);
    assertEquals(2, confValues.length);

    assertEquals("tajo.cli.print.pause=false", confValues[0]);
    assertEquals("tajo.executor.join.inner.in-memory-table-num=256", confValues[1]);

    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
    TajoCli testCli = new TajoCli(tajoConf, args, System.in, System.out);
    try {
      assertEquals("false", testCli.getContext().get(SessionVars.CLI_PAGING_ENABLED));
      assertEquals(
          "256",
          testCli.getContext().getConf().get("tajo.executor.join.inner.in-memory-table-num"));
    } finally {
      testCli.close();
    }
  }
예제 #3
0
 @Test
 public void testTimeZoneTest2() throws Exception {
   String tableName = "test1";
   tajoCli.executeMetaCommand("\\set TIMEZONE GMT+1");
   tajoCli.executeScript("create table " + tableName + " (col1 TIMESTAMP)");
   tajoCli.executeScript("insert into " + tableName + " select to_timestamp(0)");
   tajoCli.executeScript("select * from " + tableName);
   String consoleResult = new String(out.toByteArray());
   tajoCli.executeScript("DROP TABLE " + tableName + " PURGE");
   assertTrue(consoleResult.contains("1970-01-01 01:00:00"));
 }
예제 #4
0
 @After
 public void tearDown() throws IOException {
   out.close();
   if (tajoCli != null) {
     tajoCli.close();
   }
 }
예제 #5
0
  @Test
  public void testReplaceParam() throws Exception {
    String sql = "select * from lineitem where l_tax > ${tax} and l_returnflag > '${returnflag}'";
    String[] params = new String[] {"tax=10", "returnflag=A"};

    String expected = "select * from lineitem where l_tax > 10 and l_returnflag > 'A'";
    assertEquals(expected, TajoCli.replaceParam(sql, params));
  }
예제 #6
0
  @Test
  public void testShowMasters() throws Exception {
    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    TajoCli tajoCli = new TajoCli(tajoConf, new String[] {}, System.in, out);
    tajoCli.executeMetaCommand("\\admin -showmasters");

    String consoleResult = new String(out.toByteArray());

    String masterAddress =
        tajoCli.getContext().getConf().getVar(TajoConf.ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS);
    String host = masterAddress.split(":")[0];
    tajoCli.close();
    assertEquals(consoleResult, host + "\n");
  }
예제 #7
0
  @Test
  public void testGetConf() throws Exception {
    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    TajoCli tajoCli = new TajoCli(tajoConf, new String[] {}, System.in, out);
    try {
      tajoCli.executeMetaCommand("\\getconf tajo.rootdir");

      String consoleResult = new String(out.toByteArray());
      assertEquals(
          consoleResult, tajoCli.getContext().getConf().getVar(TajoConf.ConfVars.ROOT_DIR) + "\n");
    } finally {
      tajoCli.close();
    }
  }
예제 #8
0
  @Test
  public void testLocalQueryWithoutFrom() throws Exception {
    String sql = "select 'abc', '123'; select substr('123456', 1,3);";
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
    tajoCli.executeScript(sql);
    String consoleResult = new String(out.toByteArray());

    assertOutputResult(consoleResult);
  }
예제 #9
0
  private void verifyDescTable(String sql, String tableName, String resultFileName)
      throws Exception {
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
    tajoCli.executeScript(sql);

    tajoCli.executeMetaCommand("\\d " + tableName);
    tajoCli.executeMetaCommand("\\d \"" + tableName + "\"");

    String consoleResult = new String(out.toByteArray());

    if (!cluster.isHiveCatalogStoreRunning()) {
      assertOutputResult(
          resultFileName,
          consoleResult,
          new String[] {"${table.path}"},
          new String[] {
            TablespaceManager.getDefault().getTableUri("default", tableName).toString()
          });
    }
  }
예제 #10
0
  private void verifyStopWhenError() throws Exception {
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

    assertSessionVar(tajoCli, SessionVars.ON_ERROR_STOP.keyname(), "true");

    tajoCli.executeScript(
        "select count(*) from lineitem; "
            + "select count(*) from lineitem2; "
            + "select count(*) from orders");

    String consoleResult = new String(out.toByteArray());
    assertOutputResult(consoleResult);
  }
예제 #11
0
  @Test(timeout = 3000)
  public void testNonForwardQueryPause() throws Exception {
    final String sql = "select * from default.lineitem";
    TajoCli cli = null;
    try {
      TableDesc tableDesc = cluster.getMaster().getCatalog().getTableDesc("default", "lineitem");
      assertNotNull(tableDesc);
      assertEquals(0L, tableDesc.getStats().getNumRows().longValue());

      InputStream testInput =
          new ByteArrayInputStream(new byte[] {(byte) DefaultTajoCliOutputFormatter.QUIT_COMMAND});
      cli = new TajoCli(cluster.getConfiguration(), new String[] {}, testInput, out);
      setVar(cli, SessionVars.CLI_PAGE_ROWS, "2");
      setVar(cli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

      cli.executeScript(sql);

      String consoleResult;
      consoleResult = new String(out.toByteArray());
      assertOutputResult(consoleResult);
    } finally {
      cli.close();
    }
  }
예제 #12
0
  @Test
  public void testSelectResultWithNullFalse() throws Exception {
    String sql =
        "select\n"
            + "  c_custkey,\n"
            + "  orders.o_orderkey,\n"
            + "  orders.o_orderstatus \n"
            + "from\n"
            + "  orders full outer join customer on c_custkey = o_orderkey\n"
            + "order by\n"
            + "  c_custkey,\n"
            + "  orders.o_orderkey;\n";

    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
    tajoCli.executeScript(sql);

    String consoleResult = new String(out.toByteArray());
    assertOutputResult(consoleResult);
  }
예제 #13
0
  @Test
  public void testAlterTableAddDropPartition() throws Exception {
    String tableName = CatalogUtil.normalizeIdentifier("testAlterTableAddPartition");

    tajoCli.executeScript(
        "create table " + tableName + " (col1 int4, col2 int4) partition by column(key float8)");
    tajoCli.executeScript("alter table " + tableName + " add partition (key2 = 0.1)");
    tajoCli.executeScript("alter table " + tableName + " add partition (key = 0.1)");
    tajoCli.executeScript("alter table " + tableName + " drop partition (key = 0.1)");
    tajoCli.executeScript("alter table " + tableName + " drop partition (key = 0.1)");

    tajoCli.executeScript("drop table " + tableName);
    tajoCli.executeScript(
        "create table "
            + tableName
            + " (col1 int4, col2 int4) partition by column(col3 float8, col4 int4)");

    TajoClient client = testBase.getTestingCluster().newTajoClient();
    TableDesc tableDesc = client.getTableDesc(tableName);

    String partitionLocation = tableDesc.getUri().toString() + "/col5=0.1/col6=10";
    tajoCli.executeScript(
        "alter table "
            + tableName
            + " add partition (col3 = 0.1, col4 = 10)"
            + " location '"
            + partitionLocation
            + "'");

    Path partitionPath = new Path(partitionLocation);
    FileSystem fs = testBase.getTestingCluster().getDefaultFileSystem();
    assertTrue(fs.exists(partitionPath));

    tajoCli.executeScript("alter table " + tableName + " drop partition (col3 = 0.1, col4 = 10)");

    String consoleResult = new String(out.toByteArray());
    assertOutputResult(consoleResult);
  }
예제 #14
0
  @Test
  public void testConnectDatabase() throws Exception {
    String databaseName;

    if (cluster.isHiveCatalogStoreRunning()) {
      databaseName = "TEST_CONNECTION_DATABASE".toLowerCase();
    } else {
      databaseName = "TEST_CONNECTION_DATABASE";
    }
    String sql = "create database \"" + databaseName + "\";";

    tajoCli.executeScript(sql);

    tajoCli.executeMetaCommand("\\c " + databaseName);
    assertEquals(databaseName, tajoCli.getContext().getCurrentDatabase());

    tajoCli.executeMetaCommand("\\c default");
    assertEquals("default", tajoCli.getContext().getCurrentDatabase());

    tajoCli.executeMetaCommand("\\c \"" + databaseName + "\"");
    assertEquals(databaseName, tajoCli.getContext().getCurrentDatabase());
  }
예제 #15
0
 @Test
 public void testHelpSessionVars() throws Exception {
   tajoCli.executeMetaCommand("\\help set");
   assertOutputResult(new String(out.toByteArray()));
 }
예제 #16
0
 @Test
 public void testStopWhenError() throws Exception {
   tajoCli.executeMetaCommand("\\set ON_ERROR_STOP true");
   verifyStopWhenError();
 }
예제 #17
0
 private static void setVar(TajoCli cli, ConfigKey key, String val) throws Exception {
   cli.executeMetaCommand("\\set " + key.keyname() + " " + val);
 }
예제 #18
0
 private static void assertSessionVar(TajoCli cli, String key, String expectedVal) {
   assertEquals(cli.getContext().getCliSideVar(key), expectedVal);
 }
예제 #19
0
 @Test
 public void testStopWhenErrorDeprecated() throws Exception {
   tajoCli.executeMetaCommand("\\set tajo.cli.error.stop true");
   verifyStopWhenError();
 }