Search in sources :

Example 21 with Text

use of org.apache.drill.exec.util.Text in project drill by axbaretto.

the class TestBuilder method mapOf.

/**
 * Convenience method to create a {@link JsonStringHashMap<String, Object> map} instance with the given key value sequence.
 *
 * Key value sequence consists of key - value pairs such that a key precedes its value. For instance:
 *
 * mapOf("name", "Adam", "age", 41) corresponds to {"name": "Adam", "age": 41} in JSON.
 */
public static JsonStringHashMap<String, Object> mapOf(Object... keyValueSequence) {
    Preconditions.checkArgument(keyValueSequence.length % 2 == 0, "Length of key value sequence must be even");
    final JsonStringHashMap<String, Object> map = new JsonStringHashMap<>();
    for (int i = 0; i < keyValueSequence.length; i += 2) {
        Object value = keyValueSequence[i + 1];
        if (value instanceof CharSequence) {
            value = new Text(value.toString());
        }
        map.put(String.class.cast(keyValueSequence[i]), value);
    }
    return map;
}
Also used : Text(org.apache.drill.exec.util.Text) JsonStringHashMap(org.apache.drill.exec.util.JsonStringHashMap)

Example 22 with Text

use of org.apache.drill.exec.util.Text in project drill by axbaretto.

the class ParquetRecordReaderTest method testFileWithNulls.

@Test
public void testFileWithNulls() throws Exception {
    HashMap<String, FieldInfo> fields3 = new HashMap<>();
    ParquetTestProperties props3 = new ParquetTestProperties(1, 3000, DEFAULT_BYTES_PER_PAGE, fields3);
    // actually include null values
    Object[] valuesWithNull = { new Text(""), new Text("longer string"), null };
    props3.fields.put("a", new FieldInfo("boolean", "a", 1, valuesWithNull, TypeProtos.MinorType.BIT, props3));
    testParquetFullEngineEventBased(false, "parquet/parquet_scan_screen_read_entry_replace.json", "\"/tmp/nullable_with_nulls.parquet\"", "unused", 1, props3);
}
Also used : HashMap(java.util.HashMap) Text(org.apache.drill.exec.util.Text) Test(org.junit.Test)

Example 23 with Text

use of org.apache.drill.exec.util.Text in project drill by apache.

the class ParquetRecordReaderTest method testFileWithNulls.

@Test
public void testFileWithNulls() throws Exception {
    HashMap<String, FieldInfo> fields3 = new HashMap<>();
    ParquetTestProperties props3 = new ParquetTestProperties(1, 3000, DEFAULT_BYTES_PER_PAGE, fields3);
    // actually include null values
    Object[] valuesWithNull = { new Text(""), new Text("longer string"), null };
    props3.fields.put("a", new FieldInfo("boolean", "a", 1, valuesWithNull, TypeProtos.MinorType.BIT, props3));
    testParquetFullEngineEventBased(false, "parquet/parquet_scan_screen_read_entry_replace.json", "\"/tmp/nullable_with_nulls.parquet\"", "unused", 1, props3);
}
Also used : HashMap(java.util.HashMap) Text(org.apache.drill.exec.util.Text) Test(org.junit.Test)

Example 24 with Text

use of org.apache.drill.exec.util.Text in project drill by apache.

the class TestDrillParquetReader method hiveStringArray.

@Test
public void hiveStringArray() throws Exception {
    // Nesting 0: reading ARRAY<STRING>
    testBuilder().sqlQuery("SELECT string_arr_n_0 FROM cp.`parquet2/hive_arrays_p.parquet`").unOrdered().baselineColumns("string_arr_n_0").baselineValuesForSingleColumn(asList(new Text("First Value Of Array"), new Text("komlnp"), new Text("The Last Value"))).baselineValuesForSingleColumn(emptyList()).baselineValuesForSingleColumn(Collections.singletonList(new Text("ABCaBcA-1-2-3"))).go();
    // Nesting 1: reading ARRAY<ARRAY<STRING>>
    testBuilder().sqlQuery("SELECT string_arr_n_1 FROM cp.`parquet2/hive_arrays_p.parquet`").unOrdered().baselineColumns("string_arr_n_1").baselineValuesForSingleColumn(asList(asList(new Text("Array 0, Value 0"), new Text("Array 0, Value 1")), asList(new Text("Array 1")))).baselineValuesForSingleColumn(asList(emptyList(), emptyList())).baselineValuesForSingleColumn(asList(asList(new Text("One")))).go();
    // Nesting 2: reading ARRAY<ARRAY<ARRAY<STRING>>>
    testBuilder().sqlQuery("SELECT string_arr_n_2 FROM cp.`parquet2/hive_arrays_p.parquet` order by rid").ordered().baselineColumns("string_arr_n_2").baselineValuesForSingleColumn(asList(asList(// [0][0]
    asList(new Text("dhMGOr1QVO"), new Text("NZpzBl"), new Text("LC8mjYyOJ7l8dHUpk"))), asList(// [1][0]
    asList(new Text("JH")), // [1][1]
    asList(new Text("aVxgfxAu")), // [1][2]
    asList(new Text("fF amN8z8"))), asList(// [2][0]
    asList(new Text("denwte5R39dSb2PeG"), new Text("Gbosj97RXTvBK1w"), new Text("S3whFvN")), // [2][1]
    asList(new Text("2sNbYGQhkt303Gnu"), new Text("rwG"), new Text("SQH766A8XwHg2pTA6a"))), asList(// [3][0]
    asList(new Text("L"), new Text("khGFDtDluFNoo5hT")), // [3][1]
    asList(new Text("b8")), // [3][2]
    asList(new Text("Z"))), asList(// [4][0]
    asList(new Text("DTEuW"), new Text("b0Wt84hIl"), new Text("A1H")), // [4][1]
    asList(new Text("h2zXh3Qc"), new Text("NOcgU8"), new Text("RGfVgv2rvDG")), // [4][2]
    asList(new Text("Hfn1ov9hB7fZN"), new Text("0ZgCD3"))))).baselineValuesForSingleColumn(asList(asList(// [0][0]
    asList(new Text("nk"), new Text("HA"), new Text("CgAZCxTbTrFWJL3yM")), // [0][1]
    asList(new Text("T7fGXYwtBb"), new Text("G6vc")), // [0][2]
    asList(new Text("GrwB5j3LBy9")), // [0][3]
    asList(new Text("g7UreegD1H97"), new Text("dniQ5Ehhps7c1pBuM"), new Text("S wSNMGj7c")), // [0][4]
    asList(new Text("iWTEJS0"), new Text("4F"))), asList(// [1][0]
    asList(new Text("YpRcC01u6i6KO"), new Text("ujpMrvEfUWfKm"), new Text("2d")), // [1][1]
    asList(new Text("2"), new Text("HVDH"), new Text("5Qx Q6W112"))))).baselineValuesForSingleColumn(asList(asList(// [0][0]
    asList(new Text("S8d2vjNu680hSim6iJ")), // [0][1]
    asList(new Text("lRLaT9RvvgzhZ3C"), new Text("igSX1CP"), new Text("FFZMwMvAOod8")), // [0][2]
    asList(new Text("iBX"), new Text("sG")), // [0][3]
    asList(new Text("ChRjuDPz99WeU9"), new Text("2gBBmMUXV9E5E"), new Text(" VkEARI2upO"))), asList(// [1][0]
    asList(new Text("UgMok3Q5wmd")), // [1][1]
    asList(new Text("8Zf9CLfUSWK"), new Text(""), new Text("NZ7v")), // [1][2]
    asList(new Text("vQE3I5t26"), new Text("251BeQJue"))), asList(// [2][0]
    asList(new Text("Rpo8"))), asList(// [3][0]
    asList(new Text("jj3njyupewOM Ej0pu"), new Text("aePLtGgtyu4aJ5"), new Text("cKHSvNbImH1MkQmw0Cs")), // [3][1]
    asList(new Text("VSO5JgI2x7TnK31L5"), new Text("hIub"), new Text("eoBSa0zUFlwroSucU")), // [3][2]
    asList(new Text("V8Gny91lT"), new Text("5hBncDZ"))), asList(// [4][0]
    asList(new Text("Y3"), new Text("StcgywfU"), new Text("BFTDChc")), // [4][1]
    asList(new Text("5JNwXc2UHLld7"), new Text("v")), // [4][2]
    asList(new Text("9UwBhJMSDftPKuGC")), // [4][3]
    asList(new Text("E hQ9NJkc0GcMlB"), new Text("IVND1Xp1Nnw26DrL9"))))).go();
}
Also used : Text(org.apache.drill.exec.util.Text) ParquetTest(org.apache.drill.categories.ParquetTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 25 with Text

use of org.apache.drill.exec.util.Text in project drill by apache.

the class TestDrillParquetReader method hiveCharArray.

@Test
public void hiveCharArray() throws Exception {
    // Nesting 0: reading ARRAY<CHAR(2)>
    testBuilder().sqlQuery("SELECT char_arr_n_0 FROM cp.`parquet2/hive_arrays_p.parquet`").unOrdered().baselineColumns("char_arr_n_0").baselineValuesForSingleColumn(asList(new Text("aa"), new Text("cc"), new Text("ot"))).baselineValuesForSingleColumn(emptyList()).baselineValuesForSingleColumn(asList(new Text("+a"), new Text("-c"), new Text("*t"))).go();
    // Nesting 1: reading ARRAY<ARRAY<CHAR(2)>>
    testBuilder().sqlQuery("SELECT char_arr_n_1 FROM cp.`parquet2/hive_arrays_p.parquet`").unOrdered().baselineColumns("char_arr_n_1").baselineValuesForSingleColumn(asList(asList(new Text("aa")), asList(new Text("cc"), new Text("ot")))).baselineValuesForSingleColumn(asList(emptyList(), emptyList())).baselineValuesForSingleColumn(asList(asList(new Text("*t")))).go();
    // Nesting 2: reading ARRAY<ARRAY<ARRAY<CHAR(2)>>>
    testBuilder().sqlQuery("SELECT char_arr_n_2 FROM cp.`parquet2/hive_arrays_p.parquet` order by rid").ordered().baselineColumns("char_arr_n_2").baselineValuesForSingleColumn(asList(asList(// [0][0]
    asList(new Text("eT"))), asList(// [1][0]
    asList(new Text("w9"), new Text("fC"), new Text("ww")), // [1][1]
    asList(new Text("3o"), new Text("f7"), new Text("Za")), // [1][2]
    asList(new Text("lX"), new Text("iv"), new Text("jI"))), asList(// [2][0]
    asList(new Text("S3"), new Text("Qa"), new Text("aG")), // [2][1]
    asList(new Text("bj"), new Text("gc"), new Text("NO"))))).baselineValuesForSingleColumn(asList(asList(// [0][0]
    asList(new Text("PV"), new Text("tH"), new Text("B7")), // [0][1]
    asList(new Text("uL")), // [0][2]
    asList(new Text("7b"), new Text("uf")), // [0][3]
    asList(new Text("zj")), // [0][4]
    asList(new Text("sA"), new Text("hf"), new Text("hR"))))).baselineValuesForSingleColumn(asList(asList(// [0][0]
    asList(new Text("W1"), new Text("FS")), // [0][1]
    asList(new Text("le"), new Text("c0")), // [0][2]
    asList(new Text(""), new Text("0v"))), asList(// [1][0]
    asList(new Text("gj"))))).go();
}
Also used : Text(org.apache.drill.exec.util.Text) ParquetTest(org.apache.drill.categories.ParquetTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Aggregations

Text (org.apache.drill.exec.util.Text)36 Test (org.junit.Test)22 JsonStringHashMap (org.apache.drill.exec.util.JsonStringHashMap)14 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)10 FlattenPOP (org.apache.drill.exec.physical.config.FlattenPOP)10 JsonStringArrayList (org.apache.drill.exec.util.JsonStringArrayList)8 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)6 TreeMap (java.util.TreeMap)5 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)5 LegacyOperatorTestBuilder (org.apache.drill.test.LegacyOperatorTestBuilder)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 HashMap (java.util.HashMap)4 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 BatchSchema (org.apache.drill.exec.record.BatchSchema)4 MaterializedField (org.apache.drill.exec.record.MaterializedField)4 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)4 SelectionVector2 (org.apache.drill.exec.record.selection.SelectionVector2)4 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)4 ValueVector (org.apache.drill.exec.vector.ValueVector)4 BufferedWriter (java.io.BufferedWriter)3