Package org.apache.tajo.algebra

Examples of org.apache.tajo.algebra.CreateTable


  @Test
  public void testCreateTablePartitionByHash1() throws IOException {
    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_partition_by_hash_1.sql"));
    Expr expr = parseQuery(sql);
    assertEquals(OpType.CreateTable, expr.getType());
    CreateTable createTable = (CreateTable) expr;
    assertTrue(createTable.hasPartition());
    assertEquals(CreateTable.PartitionType.HASH, createTable.getPartitionMethod().getPartitionType());
    CreateTable.HashPartition hashPartition = createTable.getPartitionMethod();
    assertEquals("col1", hashPartition.getColumns()[0].getCanonicalName());
    assertTrue(hashPartition.hasQuantifier());
  }
View Full Code Here


  @Test
  public void testCreateTablePartitionByHash2() throws IOException {
    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_partition_by_hash_2.sql"));
    Expr expr = parseQuery(sql);
    assertEquals(OpType.CreateTable, expr.getType());
    CreateTable createTable = (CreateTable) expr;
    assertTrue(createTable.hasPartition());
    assertEquals(CreateTable.PartitionType.HASH, createTable.getPartitionMethod().getPartitionType());
    CreateTable.HashPartition hashPartition = createTable.getPartitionMethod();
    assertEquals("col1", hashPartition.getColumns()[0].getCanonicalName());
    assertTrue(hashPartition.hasSpecifiers());
    assertEquals(3, hashPartition.getSpecifiers().size());
  }
View Full Code Here

  @Test
  public void testCreateTablePartitionByRange() throws IOException {
    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_partition_by_range.sql"));
    Expr expr = parseQuery(sql);
    assertEquals(OpType.CreateTable, expr.getType());
    CreateTable createTable = (CreateTable) expr;
    assertTrue(createTable.hasPartition());
    assertEquals(CreateTable.PartitionType.RANGE, createTable.getPartitionMethod().getPartitionType());
    CreateTable.RangePartition rangePartition = createTable.getPartitionMethod();
    assertEquals("col1", rangePartition.getColumns()[0].getCanonicalName());
    assertEquals(3, rangePartition.getSpecifiers().size());
  }
View Full Code Here

  @Test
  public void testCreateTablePartitionByList() throws IOException {
    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_partition_by_list.sql"));
    Expr expr = parseQuery(sql);
    assertEquals(OpType.CreateTable, expr.getType());
    CreateTable createTable = (CreateTable) expr;
    assertTrue(createTable.hasPartition());
    assertEquals(CreateTable.PartitionType.LIST, createTable.getPartitionMethod().getPartitionType());
    CreateTable.ListPartition listPartition = createTable.getPartitionMethod();
    assertEquals("col1", listPartition.getColumns()[0].getCanonicalName());
    assertEquals(2, listPartition.getSpecifiers().size());
    Iterator<CreateTable.ListPartitionSpecifier> iterator = listPartition.getSpecifiers().iterator();
    CreateTable.ListPartitionSpecifier specifier = iterator.next();
    LiteralValue value1 = (LiteralValue) specifier.getValueList().getValues()[0];
View Full Code Here

  @Test
  public void testCreateTablePartitionByColumn() throws IOException {
    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_partition_by_column.sql"));
    Expr expr = parseQuery(sql);
    assertEquals(OpType.CreateTable, expr.getType());
    CreateTable createTable = (CreateTable) expr;
    assertTrue(createTable.hasPartition());
    assertEquals(CreateTable.PartitionType.COLUMN, createTable.getPartitionMethod().getPartitionType());
    CreateTable.ColumnPartition columnPartition = createTable.getPartitionMethod();
    assertEquals(3, columnPartition.getColumns().length);
    assertEquals("col3", columnPartition.getColumns()[0].getColumnName());
    assertEquals("col4", columnPartition.getColumns()[1].getColumnName());
    assertEquals("col5", columnPartition.getColumns()[2].getColumnName());
  }
View Full Code Here

  }

  @Override
  public Expr visitCreate_table_statement(SQLParser.Create_table_statementContext ctx) {
    String tableName = ctx.table_name().getText();
    CreateTable createTable = new CreateTable(tableName, checkIfExist(ctx.if_not_exists()));

    if (checkIfExist(ctx.EXTERNAL())) {
      createTable.setExternal();

      ColumnDefinition[] elements = getDefinitions(ctx.table_elements());
      String fileType = ctx.file_type.getText();
      String path = stripQuote(ctx.path.getText());

      createTable.setTableElements(elements);
      createTable.setStorageType(fileType);
      createTable.setLocation(path);
    } else {
      if (checkIfExist(ctx.table_elements())) {
        ColumnDefinition[] elements = getDefinitions(ctx.table_elements());
        createTable.setTableElements(elements);
      }

      if (checkIfExist(ctx.USING())) {
        String fileType = ctx.file_type.getText();
        createTable.setStorageType(fileType);
      }

      if (checkIfExist(ctx.query_expression())) {
        Expr subquery = visitQuery_expression(ctx.query_expression());
        createTable.setSubQuery(subquery);
      }
    }

    if (checkIfExist(ctx.param_clause())) {
      Map<String, String> params = escapeTableMeta(getParams(ctx.param_clause()));
      createTable.setParams(params);
    }

    if (checkIfExist(ctx.table_partitioning_clauses())) {
      PartitionMethodDescExpr partitionMethodDesc =
          parseTablePartitioningClause(ctx.table_partitioning_clauses());
      createTable.setPartitionMethod(partitionMethodDesc);
    }
    return createTable;
  }
View Full Code Here

TOP

Related Classes of org.apache.tajo.algebra.CreateTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.