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()]);
}
Aggregations