Last active
December 25, 2015 04:59
-
-
Save thdxr/6920880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To run the program in standalone mode, we need the following jars in the classpath from hive/build/dist/lib | |
hive_exec.jar | |
hive_jdbc.jar | |
hive_metastore.jar | |
hive_service.jar | |
libfb303.jar | |
log4j-1.2.15.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.SQLException; | |
public class Example { | |
public static void main() { | |
HiveClient client = new HiveClient(); | |
try { | |
client.Connect(); | |
HiveClient.Provider p = client.GetProvider(123123123); | |
System.out.printf("%s %s%n", p.getFirst(), p.getLast()); | |
} catch (SQLException e) { | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.SQLException; | |
import java.sql.Connection; | |
import java.sql.ResultSet; | |
import java.sql.Statement; | |
import java.sql.DriverManager; | |
public class HiveClient { | |
private Connection _connection; | |
public HiveClient() { | |
String driver = "org.apache.hadoop.hive.jdbc.HiveDriver"; | |
try { | |
Class.forName(driver); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
} | |
public void Connect() throws SQLException { | |
_connection = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", ""); | |
} | |
public class Provider { | |
private int _npi; | |
private String _organization; | |
private String _first; | |
private String _last; | |
private String _taxonomy; | |
private Provider(ResultSet rs) throws SQLException { | |
_npi = rs.getInt(0); | |
_organization = rs.getString(1); | |
_first = rs.getString(2); | |
_last = rs.getString(3); | |
_taxonomy = rs.getString(4); | |
} | |
public int getNpi() { | |
return _npi; | |
} | |
public String getOrganization() { | |
return _organization; | |
} | |
public String getFirst() { | |
return _first; | |
} | |
public String getLast() { | |
return _last; | |
} | |
public String getName() { | |
return _first + " " + _last; | |
} | |
public String getTaxonomy() { | |
return _taxonomy; | |
} | |
} | |
public Provider GetProvider(int npi) throws SQLException { | |
Statement stmt = _connection.createStatement(); | |
String sql = "" + | |
"SELECT npi, provider_organization_name_legal_business_name_,provider_first_name,provider_last_name,healthcare_provider_taxonomy_code_1" + | |
"FROM providers" + | |
"WHERE providers.npi = " + npi; | |
ResultSet res = stmt.executeQuery(sql); | |
res.next(); | |
return new Provider(res); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment