Search in sources :

Example 1 with InputSplitWithLocationInfo

use of org.apache.hadoop.mapred.InputSplitWithLocationInfo in project hive by apache.

the class LlapBaseInputFormat method getSplits.

@Override
public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
    List<InputSplit> ins = new ArrayList<InputSplit>();
    if (url == null)
        url = job.get(URL_KEY);
    if (query == null)
        query = job.get(QUERY_KEY);
    if (user == null)
        user = job.get(USER_KEY);
    if (pwd == null)
        pwd = job.get(PWD_KEY);
    if (url == null || query == null) {
        throw new IllegalStateException();
    }
    try {
        Class.forName(driverName);
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    }
    String escapedQuery = StringUtils.escapeString(query, ESCAPE_CHAR, escapedChars);
    String sql = String.format(SPLIT_QUERY, escapedQuery, numSplits);
    try (Connection con = DriverManager.getConnection(url, user, pwd);
        Statement stmt = con.createStatement();
        ResultSet res = stmt.executeQuery(sql)) {
        while (res.next()) {
            // deserialize split
            DataInput in = new DataInputStream(res.getBinaryStream(1));
            InputSplitWithLocationInfo is = new LlapInputSplit();
            is.readFields(in);
            ins.add(is);
        }
    } catch (Exception e) {
        throw new IOException(e);
    }
    return ins.toArray(new InputSplit[ins.size()]);
}
Also used : InputSplitWithLocationInfo(org.apache.hadoop.mapred.InputSplitWithLocationInfo) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException) DataInput(java.io.DataInput) ResultSet(java.sql.ResultSet) InputSplit(org.apache.hadoop.mapred.InputSplit)

Aggregations

ByteString (com.google.protobuf.ByteString)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 InputSplit (org.apache.hadoop.mapred.InputSplit)1 InputSplitWithLocationInfo (org.apache.hadoop.mapred.InputSplitWithLocationInfo)1