use of java.sql.DatabaseMetaData in project hive by apache.
the class TestJdbcDriver2 method testImportedKeys.
/**
* test getImportedKeys()
* @throws SQLException
*/
@Test
public void testImportedKeys() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
// currently getImportedKeys always returns an empty resultset for Hive
ResultSet res = dbmd.getImportedKeys(null, null, null);
ResultSetMetaData md = res.getMetaData();
assertEquals(md.getColumnCount(), 14);
assertFalse(res.next());
}
use of java.sql.DatabaseMetaData in project hive by apache.
the class TestJdbcDriver2 method testProcCols.
/**
* test getProcedureColumns()
* @throws SQLException
*/
@Test
public void testProcCols() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
// currently getProcedureColumns always returns an empty resultset for Hive
ResultSet res = dbmd.getProcedureColumns(null, null, null, null);
ResultSetMetaData md = res.getMetaData();
assertEquals(md.getColumnCount(), 20);
assertFalse(res.next());
}
use of java.sql.DatabaseMetaData in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method testDatabaseMetaData.
@Test
public void testDatabaseMetaData() throws SQLException {
DatabaseMetaData meta = con.getMetaData();
assertEquals("Apache Hive", meta.getDatabaseProductName());
assertEquals(HiveVersionInfo.getVersion(), meta.getDatabaseProductVersion());
assertEquals(System.getProperty("hive.version"), meta.getDatabaseProductVersion());
assertTrue("verifying hive version pattern. got " + meta.getDatabaseProductVersion(), Pattern.matches("\\d+\\.\\d+\\.\\d+.*", meta.getDatabaseProductVersion()));
assertEquals(DatabaseMetaData.sqlStateSQL99, meta.getSQLStateType());
assertFalse(meta.supportsCatalogsInTableDefinitions());
assertTrue(meta.supportsSchemasInTableDefinitions());
assertTrue(meta.supportsSchemasInDataManipulation());
assertFalse(meta.supportsMultipleResultSets());
assertFalse(meta.supportsStoredProcedures());
assertTrue(meta.supportsAlterTableWithAddColumn());
//-1 indicates malformed version.
assertTrue(meta.getDatabaseMajorVersion() > -1);
assertTrue(meta.getDatabaseMinorVersion() > -1);
}
use of java.sql.DatabaseMetaData in project zeppelin by apache.
the class SqlCompleter method getSqlKeywordsCompletions.
public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, SQLException {
// Add the default SQL completions
String keywords = new BufferedReader(new InputStreamReader(SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine();
Set<String> completions = new TreeSet<>();
if (null != connection) {
DatabaseMetaData metaData = connection.getMetaData();
// Add the driver specific SQL completions
String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase() + "-sql.keywords";
logger.info("JDBC DriverName:" + driverSpecificKeywords);
try {
if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
String driverKeywords = new BufferedReader(new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords))).readLine();
keywords += "," + driverKeywords.toUpperCase();
}
} catch (Exception e) {
logger.debug("fail to get driver specific SQL completions for " + driverSpecificKeywords + " : " + e, e);
}
// Add the keywords from the current JDBC connection
try {
keywords += "," + metaData.getSQLKeywords();
} catch (Exception e) {
logger.debug("fail to get SQL key words from database metadata: " + e, e);
}
try {
keywords += "," + metaData.getStringFunctions();
} catch (Exception e) {
logger.debug("fail to get string function names from database metadata: " + e, e);
}
try {
keywords += "," + metaData.getNumericFunctions();
} catch (Exception e) {
logger.debug("fail to get numeric function names from database metadata: " + e, e);
}
try {
keywords += "," + metaData.getSystemFunctions();
} catch (Exception e) {
logger.debug("fail to get system function names from database metadata: " + e, e);
}
try {
keywords += "," + metaData.getTimeDateFunctions();
} catch (Exception e) {
logger.debug("fail to get time date function names from database metadata: " + e, e);
}
// Set all keywords to lower-case versions
keywords = keywords.toLowerCase();
}
StringTokenizer tok = new StringTokenizer(keywords, ", ");
while (tok.hasMoreTokens()) {
completions.add(tok.nextToken());
}
return completions;
}
use of java.sql.DatabaseMetaData in project sharding-jdbc by dangdangdotcom.
the class ShardingDataSourceFactoryTest method createShardingRule.
private ShardingRule createShardingRule() throws SQLException {
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(databaseMetaData.getDatabaseProductName()).thenReturn("H2");
Map<String, DataSource> dataSourceMap = new HashMap<>(1);
dataSourceMap.put("ds", dataSource);
DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
TableRule tableRule = TableRule.builder("logicTable").actualTables(Arrays.asList("table_0", "table_1", "table_2")).dataSourceRule(dataSourceRule).build();
return ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Collections.singletonList(tableRule)).build();
}
Aggregations