drill-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DRILL-4047) Select with options
Date Sun, 15 Nov 2015 19:59:10 GMT

    [ https://issues.apache.org/jira/browse/DRILL-4047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15006011#comment-15006011
] 

ASF GitHub Bot commented on DRILL-4047:
---------------------------------------

Github user jacques-n commented on a diff in the pull request:

    https://github.com/apache/drill/pull/246#discussion_r44876693
  
    --- Diff: exec/java-exec/src/test/java/org/apache/drill/TestSelectWithOption.java ---
    @@ -0,0 +1,203 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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 org.apache.drill;
    +
    +import static java.lang.String.format;
    +import static org.apache.drill.TestBuilder.listOf;
    +
    +import java.io.File;
    +import java.io.FileWriter;
    +import java.io.IOException;
    +
    +import org.apache.drill.exec.store.dfs.WorkspaceSchemaFactory;
    +import org.junit.Ignore;
    +import org.junit.Test;
    +
    +public class TestSelectWithOption extends BaseTestQuery {
    +  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(WorkspaceSchemaFactory.class);
    +
    +  private File genCSVFile(String name, String... rows) throws IOException {
    +    File file = new File(format("target/%s_%s.csv", this.getClass().getName(), name));
    +    try (FileWriter fw = new FileWriter(file)) {
    +      for (int i = 0; i < rows.length; i++) {
    +        fw.append(rows[i] + "\n");
    +      }
    +    }
    +    return file;
    +  }
    +
    +  private String genCSVTable(String name, String... rows) throws IOException {
    +    File f = genCSVFile(name, rows);
    +    return format("dfs.`${WORKING_PATH}/%s`", f.getPath());
    +  }
    +
    +  private void testWithResult(String query, Object... expectedResult) throws Exception
{
    +    TestBuilder builder = testBuilder()
    +        .sqlQuery(query)
    +        .ordered()
    +        .baselineColumns("columns");
    +    for (Object o : expectedResult) {
    +      builder = builder.baselineValues(o);
    +    }
    +    builder.build().run();
    +  }
    +
    +  @Test
    +  public void testTextFieldDelimiter() throws Exception {
    +    String tableName = genCSVTable("testTextFieldDelimiter",
    +        "\"b\"|\"0\"",
    +        "\"b\"|\"1\"",
    +        "\"b\"|\"2\"");
    +
    +    String queryTemplate =
    +        "select columns from table(%s (type => 'TeXT', fieldDelimiter => '%s'))";
    +    testWithResult(format(queryTemplate, tableName, ","),
    +        listOf("b\"|\"0"),
    +        listOf("b\"|\"1"),
    +        listOf("b\"|\"2")
    +      );
    +    testWithResult(format(queryTemplate, tableName, "|"),
    +        listOf("b", "0"),
    +        listOf("b", "1"),
    +        listOf("b", "2")
    +      );
    +  }
    +
    +  @Test @Ignore // It does not look like lineDelimiter is working
    +  public void testTextLineDelimiter() throws Exception {
    +    String tableName = genCSVTable("testTextLineDelimiter",
    +        "\"b\"|\"0\"",
    +        "\"b\"|\"1\"",
    +        "\"b\"|\"2\"");
    +
    +    testWithResult(format("select columns from table(%s(type => 'TeXT', lineDelimiter
=> '|'))", tableName),
    +        listOf("\"b\""),
    +        listOf("\"0\"", "\"b\""),
    +        listOf("\"1\"", "\"b\""),
    +        listOf("\"2\"")
    +      );
    +  }
    +
    +  @Test
    +  public void testTextQuote() throws Exception {
    +    String tableName = genCSVTable("testTextQuote",
    +        "\"b\"|\"0\"",
    +        "\"b\"|\"1\"",
    +        "\"b\"|\"2\"");
    +
    +    testWithResult(format("select columns from table(%s(type => 'TeXT', fieldDelimiter
=> '|', quote => '@'))", tableName),
    +        listOf("\"b\"", "\"0\""),
    +        listOf("\"b\"", "\"1\""),
    +        listOf("\"b\"", "\"2\"")
    +        );
    +
    +    String quoteTableName = genCSVTable("testTextQuote2",
    +        "@b@|@0@",
    +        "@b$@c@|@1@");
    +    // It seems that a parameter can not be called "escape"
    +    testWithResult(format("select columns from table(%s(`escape` => '$', type =>
'TeXT', fieldDelimiter => '|', quote => '@'))", quoteTableName),
    +        listOf("b", "0"),
    +        listOf("b$@c", "1") // shouldn't $ be removed here?
    +        );
    +  }
    +
    +  @Test
    +  public void testTextComment() throws Exception {
    +      String commentTableName = genCSVTable("testTextComment",
    +          "b|0",
    +          "@ this is a comment",
    +          "b|1");
    +      testWithResult(format("select columns from table(%s(type => 'TeXT', fieldDelimiter
=> '|', comment => '@'))", commentTableName),
    +          listOf("b", "0"),
    +          listOf("b", "1")
    +          );
    +  }
    +
    +  @Test
    +  public void testTextHeader() throws Exception {
    +    String headerTableName = genCSVTable("testTextHeader",
    +        "b|a",
    +        "b|0",
    +        "b|1");
    +    testWithResult(format("select columns from table(%s(type => 'TeXT', fieldDelimiter
=> '|', skipFirstLine => true))", headerTableName),
    +        listOf("b", "0"),
    +        listOf("b", "1")
    +        );
    +
    +    testBuilder()
    +        .sqlQuery(format("select a, b from table(%s(type => 'TeXT', fieldDelimiter
=> '|', extractHeader => true))", headerTableName))
    +        .ordered()
    +        .baselineColumns("b", "a")
    +        .baselineValues("b", "0")
    +        .baselineValues("b", "1")
    +        .build().run();
    +  }
    +
    +  @Test
    +  public void testVariationsCSV() throws Exception {
    +    String csvTableName = genCSVTable("testVariationsCSV",
    +        "a,b",
    +        "c|d");
    +    // Using the defaults in TextFormatConfig (the field delimiter is neither "," not
"|")
    +    String[] csvQueries = {
    +//        format("select columns from %s ('TeXT')", csvTableName),
    +//        format("select columns from %s('TeXT')", csvTableName),
    +        format("select columns from table(%s ('TeXT'))", csvTableName),
    --- End diff --
    
    Do you have a test where data it isn't TeXT?
    



> Select with options
> -------------------
>
>                 Key: DRILL-4047
>                 URL: https://issues.apache.org/jira/browse/DRILL-4047
>             Project: Apache Drill
>          Issue Type: Improvement
>          Components: Execution - Relational Operators
>            Reporter: Julien Le Dem
>            Assignee: Julien Le Dem
>
> Add a mechanism to pass parameters down to the StoragePlugin when writing a Select statement.
> Some discussion here:
> http://mail-archives.apache.org/mod_mbox/drill-dev/201510.mbox/%3CCAO%2Bvc4AcGK3%2B3QYvQV1-xPPdpG3Tc%2BfG%3D0xDGEUPrhd6ktHv5Q%40mail.gmail.com%3E
> http://mail-archives.apache.org/mod_mbox/drill-dev/201511.mbox/%3CCAO+vc4CLzyLvJEviSFJQtcyxb-ZSmFy4bQrM-jHBiDWzGqFVJg@mail.gmail.com%3E



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message