Search in sources :

Example 1 with HeaderBuilder

use of org.apache.drill.exec.store.easy.text.reader.HeaderBuilder in project drill by apache.

the class TestHeaderBuilder method testSyntax.

@Test
public void testSyntax() {
    Path dummyPath = new Path("file:/dummy.csv");
    HeaderBuilder hb = new HeaderBuilder(dummyPath);
    parse(hb, "a_123");
    validateHeader(hb, new String[] { "a_123" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "a_123_");
    validateHeader(hb, new String[] { "a_123_" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "az09_");
    validateHeader(hb, new String[] { "az09_" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "+");
    validateHeader(hb, new String[] { "column_1" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "+,-");
    validateHeader(hb, new String[] { "column_1", "column_2" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "+9a");
    validateHeader(hb, new String[] { "col_9a" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "9a");
    validateHeader(hb, new String[] { "col_9a" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "a+b");
    validateHeader(hb, new String[] { "a_b" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "a_b");
    validateHeader(hb, new String[] { "a_b" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "EXPR$0");
    validateHeader(hb, new String[] { "EXPR_0" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "(_-^-_)");
    validateHeader(hb, new String[] { "col_______" });
}
Also used : Path(org.apache.hadoop.fs.Path) HeaderBuilder(org.apache.drill.exec.store.easy.text.reader.HeaderBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 2 with HeaderBuilder

use of org.apache.drill.exec.store.easy.text.reader.HeaderBuilder in project drill by apache.

the class TestHeaderBuilder method testParser.

private void testParser(String input, String[] expected) {
    Path dummyPath = new Path("file:/dummy.csv");
    HeaderBuilder hb = new HeaderBuilder(dummyPath);
    parse(hb, input);
    hb.finishRecord();
    validateHeader(hb, expected);
}
Also used : Path(org.apache.hadoop.fs.Path) HeaderBuilder(org.apache.drill.exec.store.easy.text.reader.HeaderBuilder)

Example 3 with HeaderBuilder

use of org.apache.drill.exec.store.easy.text.reader.HeaderBuilder in project drill by apache.

the class TestHeaderBuilder method testWhiteSpace.

@Test
public void testWhiteSpace() {
    Path dummyPath = new Path("file:/dummy.csv");
    HeaderBuilder hb = new HeaderBuilder(dummyPath);
    parse(hb, "a");
    validateHeader(hb, new String[] { "a" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, " a ");
    validateHeader(hb, new String[] { "a" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "    a    ");
    validateHeader(hb, new String[] { "a" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "a,b,c");
    validateHeader(hb, new String[] { "a", "b", "c" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, " a , b ,  c ");
    validateHeader(hb, new String[] { "a", "b", "c" });
}
Also used : Path(org.apache.hadoop.fs.Path) HeaderBuilder(org.apache.drill.exec.store.easy.text.reader.HeaderBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 4 with HeaderBuilder

use of org.apache.drill.exec.store.easy.text.reader.HeaderBuilder in project drill by apache.

the class TestHeaderBuilder method testEmptyHeader.

@Test
public void testEmptyHeader() {
    Path dummyPath = new Path("file:/dummy.csv");
    HeaderBuilder hb = new HeaderBuilder(dummyPath);
    try {
        hb.finishRecord();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("must define at least one header"));
    }
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "");
    try {
        hb.finishRecord();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("must define at least one header"));
    }
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "   ");
    validateHeader(hb, new String[] { "column_1" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, ",");
    validateHeader(hb, new String[] { "column_1", "column_2" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, " , ");
    validateHeader(hb, new String[] { "column_1", "column_2" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "a,   ");
    validateHeader(hb, new String[] { "a", "column_2" });
}
Also used : Path(org.apache.hadoop.fs.Path) HeaderBuilder(org.apache.drill.exec.store.easy.text.reader.HeaderBuilder) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 5 with HeaderBuilder

use of org.apache.drill.exec.store.easy.text.reader.HeaderBuilder in project drill by apache.

the class TestHeaderBuilder method testUnicode.

@Test
public void testUnicode() {
    Path dummyPath = new Path("file:/dummy.csv");
    HeaderBuilder hb = new HeaderBuilder(dummyPath);
    parse(hb, "Αθήνα");
    validateHeader(hb, new String[] { "Αθήνα" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "Москва");
    validateHeader(hb, new String[] { "Москва" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "Paris,Αθήνα,Москва");
    validateHeader(hb, new String[] { "Paris", "Αθήνα", "Москва" });
}
Also used : Path(org.apache.hadoop.fs.Path) HeaderBuilder(org.apache.drill.exec.store.easy.text.reader.HeaderBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Aggregations

HeaderBuilder (org.apache.drill.exec.store.easy.text.reader.HeaderBuilder)5 Path (org.apache.hadoop.fs.Path)5 DrillTest (org.apache.drill.test.DrillTest)4 Test (org.junit.Test)4 UserException (org.apache.drill.common.exceptions.UserException)1