Package org.apache.tajo.catalog

Examples of org.apache.tajo.catalog.Schema


    testEval(schema, "table1", "abc,2,3.14", "select col1 || '---' || col3 from table1", new String[]{"abc---3.14"});
  }

  @Test
  public void testLTrim() throws IOException {
    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);

    testSimpleEval("select ltrim(' trim') ", new String[]{"trim"});
    testSimpleEval("select ltrim('xxtrim', 'xx') ", new String[]{"trim"});

    testSimpleEval("select trim(leading 'xx' from 'xxtrim') ", new String[]{"trim"});
View Full Code Here


        new String[]{"trimabc"});
  }

  @Test
  public void testRTrim() throws IOException {
    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);

    testSimpleEval("select rtrim('trim ') ", new String[]{"trim"});
    testSimpleEval("select rtrim('trimxx', 'xx') ", new String[]{"trim"});

    testSimpleEval("select trim(trailing 'xx' from 'trimxx') ", new String[]{"trim"});
View Full Code Here

        new String[]{"trimabc"});
  }

  @Test
  public void testTrim() throws IOException {
    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);

    testSimpleEval("select trim(' trim ') ", new String[]{"trim"});
    testSimpleEval("select btrim('xxtrimxx', 'xx') ", new String[]{"trim"});

    testSimpleEval("select trim(both 'xx' from 'xxtrimxx') ", new String[]{"trim"});
View Full Code Here

    // null test
    // testSimpleEval("select regexp_replace(null, 'bc', '--') as col1 ", new String[]{""});
    // testSimpleEval("select regexp_replace('abcdef', null, '--') as col1 ", new String[]{""});
    // testSimpleEval("select regexp_replace('abcdef','bc', null) as col1 ", new String[]{""});

    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);
    schema.addColumn("col3", TEXT);

    // find matches and replace from column values
    testEval(schema, "table1", "------,(^--|--$),ab", "select regexp_replace(col1, col2, col3) as str from table1",
        new String[]{"ab--ab"});
View Full Code Here

  @Test
  public void testUpper() throws IOException {
    testSimpleEval("select upper('abcdef') as col1 ", new String[]{"ABCDEF"});

    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);
    schema.addColumn("col3", TEXT);
    testEval(schema, "table1", "abc,efg,3.14", "select upper(col1), upper(col2) from table1",
        new String[]{"ABC", "EFG"});
    testEval(schema, "table1", "abc,efg,3.14", "select upper(col1) || upper(col2) from table1", new String[]{"ABCEFG"});
  }
View Full Code Here

  @Test
  public void testLower() throws IOException {
    testSimpleEval("select lower('ABCdEF') as col1 ", new String[]{"abcdef"});

    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);
    schema.addColumn("col3", TEXT);
    testEval(schema, "table1", "ABC,DEF,3.14", "select lower(col1), lower(col2) from table1",
        new String[]{"abc", "def"});
    testEval(schema, "table1", "ABC,DEF,3.14", "select lower(col1) || lower(col2) from table1", new String[]{"abcdef"});
  }
View Full Code Here

  @Test
  public void testCharLength() throws IOException {
    testSimpleEval("select char_length('123456') as col1 ", new String[]{"6"});

    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);
    schema.addColumn("col3", TEXT);
    testEval(schema, "table1", "ABC,DEF,3.14", "select character_length(lower(col1) || lower(col2)) from table1",
        new String[]{"6"});
  }
View Full Code Here

    testSimpleEval("select '123'::double", new String[] {"123.0"});
  }

  @Test
  public void testCastFromTable() throws IOException {
    Schema schema = new Schema();
    schema.addColumn("col1", TEXT);
    schema.addColumn("col2", TEXT);
    testEval(schema, "table1", "123,234", "select cast(col1 as float) as b, cast(col2 as float) as a from table1",
        new String[]{"123.0", "234.0"});
    testEval(schema, "table1", "123,234", "select col1::float, col2::float from table1",
        new String[]{"123.0", "234.0"});
  }
View Full Code Here

   * In the column partitioned table, a path has an important role to
   * indicate partition keys. In this time, it is right. Later, we have to fix it.
   */
  private void rewriteColumnPartitionedTableSchema() throws IOException {
    PartitionMethodDesc partitionDesc = plan.getTableDesc().getPartitionMethod();
    Schema columnPartitionSchema = SchemaUtil.clone(partitionDesc.getExpressionSchema());
    String qualifier = inSchema.getColumn(0).getQualifier();
    columnPartitionSchema.setQualifier(qualifier);

    // Remove partition key columns from an input schema.
    this.inSchema = plan.getTableDesc().getSchema();

    List<FileFragment> fileFragments = FragmentConvertor.convert(FileFragment.class, fragments);

    // Get a partition key value from a given path
    Tuple partitionRow =
        TupleUtil.buildTupleFromPartitionPath(columnPartitionSchema, fileFragments.get(0).getPath(), false);

    // Targets or search conditions may contain column references.
    // However, actual values absent in tuples. So, Replace all column references by constant datum.
    for (Column column : columnPartitionSchema.toArray()) {
      FieldEval targetExpr = new FieldEval(column);
      Datum datum = targetExpr.eval(columnPartitionSchema, partitionRow);
      ConstEval constExpr = new ConstEval(datum);

      for (Target target : plan.getTargets()) {
View Full Code Here

      }
    }
  }

  public void init() throws IOException {
    Schema projected;

    if (fragments != null
        && plan.getTableDesc().hasPartition()
        && plan.getTableDesc().getPartitionMethod().getPartitionType() == CatalogProtos.PartitionType.COLUMN) {
      rewriteColumnPartitionedTableSchema();
    }

    if (plan.hasTargets()) {
      projected = new Schema();
      Set<Column> columnSet = new HashSet<Column>();

      if (plan.hasQual()) {
        columnSet.addAll(EvalTreeUtil.findUniqueColumns(qual));
      }

      for (Target t : plan.getTargets()) {
        columnSet.addAll(EvalTreeUtil.findUniqueColumns(t.getEvalTree()));
      }

      for (Column column : inSchema.getColumns()) {
        if (columnSet.contains(column)) {
          projected.addColumn(column);
        }
      }
    } else {
      projected = outSchema;
    }
View Full Code Here

TOP

Related Classes of org.apache.tajo.catalog.Schema

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.