Search in sources :

Example 1 with RegexBulkLoadTool

use of org.apache.phoenix.mapreduce.RegexBulkLoadTool in project phoenix by apache.

the class RegexBulkLoadToolIT method testInvalidArguments.

@Test
public void testInvalidArguments() {
    String tableName = "TABLE8";
    RegexBulkLoadTool regexBulkLoadTool = new RegexBulkLoadTool();
    regexBulkLoadTool.setConf(getUtility().getConfiguration());
    try {
        regexBulkLoadTool.run(new String[] { "--input", "/tmp/input4.csv", "--table", tableName, "--regex", "([^,]*),([^,]*),([^,]*)", "--zookeeper", zkQuorum });
        fail(String.format("Table %s not created, hence should fail", tableName));
    } catch (Exception ex) {
        assertTrue(ex instanceof IllegalArgumentException);
        assertTrue(ex.getMessage().contains(String.format("Table %s not found", tableName)));
    }
}
Also used : RegexBulkLoadTool(org.apache.phoenix.mapreduce.RegexBulkLoadTool) FileAlreadyExistsException(org.apache.hadoop.mapred.FileAlreadyExistsException) Test(org.junit.Test)

Example 2 with RegexBulkLoadTool

use of org.apache.phoenix.mapreduce.RegexBulkLoadTool in project phoenix by apache.

the class RegexBulkLoadToolIT method testFullOptionImport.

@Test
public void testFullOptionImport() throws Exception {
    Statement stmt = conn.createStatement();
    stmt.execute("CREATE TABLE TABLE2 (ID INTEGER NOT NULL PRIMARY KEY, " + "NAME VARCHAR, NAMES VARCHAR ARRAY, FLAG BOOLEAN)");
    FileSystem fs = FileSystem.get(getUtility().getConfiguration());
    FSDataOutputStream outputStream = fs.create(new Path("/tmp/input2.csv"));
    PrintWriter printWriter = new PrintWriter(outputStream);
    printWriter.println("1|Name 1a;Name 1b,true");
    printWriter.println("2|Name 2a;Name 2b,false");
    printWriter.close();
    RegexBulkLoadTool regexBulkLoadTool = new RegexBulkLoadTool();
    regexBulkLoadTool.setConf(getUtility().getConfiguration());
    int exitCode = regexBulkLoadTool.run(new String[] { "--input", "/tmp/input2.csv", "--table", "table2", "--zookeeper", zkQuorum, "--array-delimiter", ";", "--regex", "([^|]*)\\|([^,]*),([^,]*)", "--import-columns", "ID,NAMES,FLAG" });
    assertEquals(0, exitCode);
    ResultSet rs = stmt.executeQuery("SELECT id, names FROM table2 ORDER BY id");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertArrayEquals(new Object[] { "Name 1a", "Name 1b" }, (Object[]) rs.getArray(2).getArray());
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    assertArrayEquals(new Object[] { "Name 2a", "Name 2b" }, (Object[]) rs.getArray(2).getArray());
    assertFalse(rs.next());
    rs.close();
    stmt.close();
}
Also used : Path(org.apache.hadoop.fs.Path) Statement(java.sql.Statement) FileSystem(org.apache.hadoop.fs.FileSystem) ResultSet(java.sql.ResultSet) RegexBulkLoadTool(org.apache.phoenix.mapreduce.RegexBulkLoadTool) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with RegexBulkLoadTool

use of org.apache.phoenix.mapreduce.RegexBulkLoadTool in project phoenix by apache.

the class RegexBulkLoadToolIT method testInvalidRegex.

@Test
public void testInvalidRegex() throws Exception {
    Statement stmt = conn.createStatement();
    stmt.execute("CREATE TABLE TABLE10 (ID INTEGER NOT NULL PRIMARY KEY, " + "NAME VARCHAR, NAMES VARCHAR ARRAY, FLAG BOOLEAN)");
    FileSystem fs = FileSystem.get(getUtility().getConfiguration());
    FSDataOutputStream outputStream = fs.create(new Path("/tmp/input10.csv"));
    PrintWriter printWriter = new PrintWriter(outputStream);
    printWriter.println("1|Name 1a;Name 1b,true");
    printWriter.println("2|Name 2a;Name 2b");
    printWriter.close();
    RegexBulkLoadTool regexBulkLoadTool = new RegexBulkLoadTool();
    regexBulkLoadTool.setConf(getUtility().getConfiguration());
    int exitCode = regexBulkLoadTool.run(new String[] { "--input", "/tmp/input10.csv", "--table", "table10", "--zookeeper", zkQuorum, "--array-delimiter", ";", "--regex", "([^|]*)\\|([^,]*),([^,]*)", "--import-columns", "ID,NAMES,FLAG" });
    assertEquals(-1, exitCode);
    stmt.close();
}
Also used : Path(org.apache.hadoop.fs.Path) Statement(java.sql.Statement) FileSystem(org.apache.hadoop.fs.FileSystem) RegexBulkLoadTool(org.apache.phoenix.mapreduce.RegexBulkLoadTool) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 4 with RegexBulkLoadTool

use of org.apache.phoenix.mapreduce.RegexBulkLoadTool in project phoenix by apache.

the class RegexBulkLoadToolIT method testImportWithIndex.

@Test
public void testImportWithIndex() throws Exception {
    Statement stmt = conn.createStatement();
    stmt.execute("CREATE TABLE TABLE3 (ID INTEGER NOT NULL PRIMARY KEY, " + "FIRST_NAME VARCHAR, LAST_NAME VARCHAR)");
    String ddl = "CREATE INDEX TABLE3_IDX ON TABLE3 " + " (FIRST_NAME ASC)" + " INCLUDE (LAST_NAME)";
    stmt.execute(ddl);
    FileSystem fs = FileSystem.get(getUtility().getConfiguration());
    FSDataOutputStream outputStream = fs.create(new Path("/tmp/input3.csv"));
    PrintWriter printWriter = new PrintWriter(outputStream);
    printWriter.println("1,FirstName 1,LastName 1");
    printWriter.println("2,FirstName 2,LastName 2");
    printWriter.close();
    RegexBulkLoadTool regexBulkLoadTool = new RegexBulkLoadTool();
    regexBulkLoadTool.setConf(getUtility().getConfiguration());
    int exitCode = regexBulkLoadTool.run(new String[] { "--input", "/tmp/input3.csv", "--table", "table3", "--regex", "([^,]*),([^,]*),([^,]*)", "--zookeeper", zkQuorum });
    assertEquals(0, exitCode);
    ResultSet rs = stmt.executeQuery("SELECT id, FIRST_NAME FROM TABLE3 where first_name='FirstName 2'");
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    assertEquals("FirstName 2", rs.getString(2));
    rs.close();
    stmt.close();
}
Also used : Path(org.apache.hadoop.fs.Path) Statement(java.sql.Statement) FileSystem(org.apache.hadoop.fs.FileSystem) ResultSet(java.sql.ResultSet) RegexBulkLoadTool(org.apache.phoenix.mapreduce.RegexBulkLoadTool) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with RegexBulkLoadTool

use of org.apache.phoenix.mapreduce.RegexBulkLoadTool in project phoenix by apache.

the class RegexBulkLoadToolIT method testAlreadyExistsOutputPath.

@Test
public void testAlreadyExistsOutputPath() {
    String tableName = "TABLE9";
    String outputPath = "/tmp/output/tabl9";
    try {
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE " + tableName + "(ID INTEGER NOT NULL PRIMARY KEY, " + "FIRST_NAME VARCHAR, LAST_NAME VARCHAR)");
        FileSystem fs = FileSystem.get(getUtility().getConfiguration());
        fs.create(new Path(outputPath));
        FSDataOutputStream outputStream = fs.create(new Path("/tmp/input9.csv"));
        PrintWriter printWriter = new PrintWriter(outputStream);
        printWriter.println("1,FirstName 1,LastName 1");
        printWriter.println("2,FirstName 2,LastName 2");
        printWriter.close();
        RegexBulkLoadTool regexBulkLoadTool = new RegexBulkLoadTool();
        regexBulkLoadTool.setConf(getUtility().getConfiguration());
        regexBulkLoadTool.run(new String[] { "--input", "/tmp/input9.csv", "--output", outputPath, "--table", tableName, "--regex", "([^,]*),([^,]*),([^,]*)", "--zookeeper", zkQuorum });
        fail(String.format("Output path %s already exists. hence, should fail", outputPath));
    } catch (Exception ex) {
        assertTrue(ex instanceof FileAlreadyExistsException);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileAlreadyExistsException(org.apache.hadoop.mapred.FileAlreadyExistsException) Statement(java.sql.Statement) FileSystem(org.apache.hadoop.fs.FileSystem) RegexBulkLoadTool(org.apache.phoenix.mapreduce.RegexBulkLoadTool) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) FileAlreadyExistsException(org.apache.hadoop.mapred.FileAlreadyExistsException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

RegexBulkLoadTool (org.apache.phoenix.mapreduce.RegexBulkLoadTool)9 PrintWriter (java.io.PrintWriter)8 Statement (java.sql.Statement)8 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)8 FileSystem (org.apache.hadoop.fs.FileSystem)8 Path (org.apache.hadoop.fs.Path)8 Test (org.junit.Test)8 ResultSet (java.sql.ResultSet)6 FileAlreadyExistsException (org.apache.hadoop.mapred.FileAlreadyExistsException)2