PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java

http://github.com/apache/hive
Java | 1174 lines | 887 code | 222 blank | 65 comment | 53 complexity | 5cdfafc36582f067fd35559480dffd7b MD5 | raw file
Possible License(s): Apache-2.0
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.hive.jdbc;
  19. import java.sql.Connection;
  20. import java.sql.DatabaseMetaData;
  21. import java.sql.ResultSet;
  22. import java.sql.RowIdLifetime;
  23. import java.sql.SQLException;
  24. import java.util.ArrayList;
  25. import java.util.Arrays;
  26. import java.util.Collections;
  27. import java.util.Comparator;
  28. import java.util.List;
  29. import java.util.jar.Attributes;
  30. import org.apache.hadoop.hive.metastore.TableType;
  31. import org.apache.hadoop.hive.metastore.api.FieldSchema;
  32. import org.apache.hadoop.hive.metastore.api.Table;
  33. import org.apache.hadoop.hive.service.HiveInterface;
  34. import org.apache.thrift.TException;
  35. /**
  36. * HiveDatabaseMetaData.
  37. *
  38. */
  39. public class HiveDatabaseMetaData implements java.sql.DatabaseMetaData {
  40. private final HiveInterface client;
  41. private static final String CATALOG_SEPARATOR = ".";
  42. private static final char SEARCH_STRING_ESCAPE = '\\';
  43. // The maximum column length = MFieldSchema.FNAME in metastore/src/model/package.jdo
  44. private static final int maxColumnNameLength = 128;
  45. /**
  46. *
  47. */
  48. public HiveDatabaseMetaData(HiveInterface client) {
  49. this.client = client;
  50. }
  51. public boolean allProceduresAreCallable() throws SQLException {
  52. throw new SQLException("Method not supported");
  53. }
  54. public boolean allTablesAreSelectable() throws SQLException {
  55. return true;
  56. }
  57. public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
  58. throw new SQLException("Method not supported");
  59. }
  60. public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
  61. throw new SQLException("Method not supported");
  62. }
  63. public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
  64. throw new SQLException("Method not supported");
  65. }
  66. public boolean deletesAreDetected(int type) throws SQLException {
  67. throw new SQLException("Method not supported");
  68. }
  69. public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
  70. throw new SQLException("Method not supported");
  71. }
  72. public ResultSet getAttributes(String catalog, String schemaPattern,
  73. String typeNamePattern, String attributeNamePattern) throws SQLException {
  74. throw new SQLException("Method not supported");
  75. }
  76. public ResultSet getBestRowIdentifier(String catalog, String schema,
  77. String table, int scope, boolean nullable) throws SQLException {
  78. throw new SQLException("Method not supported");
  79. }
  80. public String getCatalogSeparator() throws SQLException {
  81. return CATALOG_SEPARATOR;
  82. }
  83. public String getCatalogTerm() throws SQLException {
  84. return "database";
  85. }
  86. public ResultSet getCatalogs() throws SQLException {
  87. try {
  88. // TODO a client call to get the schema's after HIVE-675 is implemented
  89. final List<String> catalogs = new ArrayList<String>();
  90. catalogs.add("default");
  91. return new HiveMetaDataResultSet<String>(Arrays.asList("TABLE_CAT")
  92. , Arrays.asList("STRING")
  93. , catalogs) {
  94. private int cnt = 0;
  95. public boolean next() throws SQLException {
  96. if (cnt<data.size()) {
  97. List<Object> a = new ArrayList<Object>(1);
  98. a.add(data.get(cnt)); // TABLE_CAT String => table catalog (may be null)
  99. row = a;
  100. cnt++;
  101. return true;
  102. } else {
  103. return false;
  104. }
  105. }
  106. public <T> T getObject(String columnLabel, Class<T> type)
  107. throws SQLException {
  108. // JDK 1.7
  109. throw new SQLException("Method not supported");
  110. }
  111. public <T> T getObject(int columnIndex, Class<T> type)
  112. throws SQLException {
  113. // JDK 1.7
  114. throw new SQLException("Method not supported");
  115. }
  116. };
  117. } catch (Exception e) {
  118. throw new SQLException(e);
  119. }
  120. }
  121. public ResultSet getClientInfoProperties() throws SQLException {
  122. throw new SQLException("Method not supported");
  123. }
  124. public ResultSet getColumnPrivileges(String catalog, String schema,
  125. String table, String columnNamePattern) throws SQLException {
  126. throw new SQLException("Method not supported");
  127. }
  128. public ResultSet getPseudoColumns(String catalog, String schemaPattern,
  129. String tableNamePattern, String columnNamePattern) throws SQLException {
  130. throw new SQLException("Method not supported");
  131. }
  132. public boolean generatedKeyAlwaysReturned() throws SQLException {
  133. // JDK 1.7
  134. throw new SQLException("Method not supported");
  135. }
  136. /**
  137. * Convert a pattern containing JDBC catalog search wildcards into
  138. * Java regex patterns.
  139. *
  140. * @param pattern input which may contain '%' or '_' wildcard characters, or
  141. * these characters escaped using {@link #getSearchStringEscape()}.
  142. * @return replace %/_ with regex search characters, also handle escaped
  143. * characters.
  144. */
  145. private String convertPattern(final String pattern) {
  146. if (pattern==null) {
  147. return ".*";
  148. } else {
  149. StringBuilder result = new StringBuilder(pattern.length());
  150. boolean escaped = false;
  151. for (int i = 0, len = pattern.length(); i < len; i++) {
  152. char c = pattern.charAt(i);
  153. if (escaped) {
  154. if (c != SEARCH_STRING_ESCAPE) {
  155. escaped = false;
  156. }
  157. result.append(c);
  158. } else {
  159. if (c == SEARCH_STRING_ESCAPE) {
  160. escaped = true;
  161. continue;
  162. } else if (c == '%') {
  163. result.append(".*");
  164. } else if (c == '_') {
  165. result.append('.');
  166. } else {
  167. result.append(Character.toLowerCase(c));
  168. }
  169. }
  170. }
  171. return result.toString();
  172. }
  173. }
  174. public ResultSet getColumns(String catalog, final String schemaPattern
  175. , final String tableNamePattern
  176. , final String columnNamePattern) throws SQLException {
  177. List<JdbcColumn> columns = new ArrayList<JdbcColumn>();
  178. try {
  179. if (catalog==null) {
  180. catalog = "default";
  181. }
  182. String regtableNamePattern = convertPattern(tableNamePattern);
  183. String regcolumnNamePattern = convertPattern(columnNamePattern);
  184. List<String> tables = client.get_tables(catalog, "*");
  185. for (String table: tables) {
  186. if (table.matches(regtableNamePattern)) {
  187. List<FieldSchema> fields = client.get_schema(catalog, table);
  188. int ordinalPos = 1;
  189. for (FieldSchema field: fields) {
  190. if (field.getName().matches(regcolumnNamePattern)) {
  191. columns.add(new JdbcColumn(field.getName(), table, catalog
  192. , field.getType(), field.getComment(), ordinalPos));
  193. ordinalPos++;
  194. }
  195. }
  196. }
  197. }
  198. Collections.sort(columns, new GetColumnsComparator());
  199. return new HiveMetaDataResultSet<JdbcColumn>(
  200. Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE"
  201. , "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS"
  202. , "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE"
  203. , "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION"
  204. , "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE"
  205. , "SOURCE_DATA_TYPE")
  206. , Arrays.asList("STRING", "STRING", "STRING", "STRING", "INT", "STRING"
  207. , "INT", "INT", "INT", "INT", "INT", "STRING"
  208. , "STRING", "INT", "INT", "INT", "INT"
  209. , "STRING", "STRING", "STRING", "STRING", "INT")
  210. , columns) {
  211. private int cnt = 0;
  212. public boolean next() throws SQLException {
  213. if (cnt<data.size()) {
  214. List<Object> a = new ArrayList<Object>(20);
  215. JdbcColumn column = data.get(cnt);
  216. a.add(column.getTableCatalog()); // TABLE_CAT String => table catalog (may be null)
  217. a.add(null); // TABLE_SCHEM String => table schema (may be null)
  218. a.add(column.getTableName()); // TABLE_NAME String => table name
  219. a.add(column.getColumnName()); // COLUMN_NAME String => column name
  220. a.add(column.getSqlType()); // DATA_TYPE short => SQL type from java.sql.Types
  221. a.add(column.getType()); // TYPE_NAME String => Data source dependent type name.
  222. a.add(column.getColumnSize()); // COLUMN_SIZE int => column size.
  223. a.add(null); // BUFFER_LENGTH is not used.
  224. a.add(column.getDecimalDigits()); // DECIMAL_DIGITS int => number of fractional digits
  225. a.add(column.getNumPrecRadix()); // NUM_PREC_RADIX int => typically either 10 or 2
  226. a.add(DatabaseMetaData.columnNullable); // NULLABLE int => is NULL allowed?
  227. a.add(column.getComment()); // REMARKS String => comment describing column (may be null)
  228. a.add(null); // COLUMN_DEF String => default value (may be null)
  229. a.add(null); // SQL_DATA_TYPE int => unused
  230. a.add(null); // SQL_DATETIME_SUB int => unused
  231. a.add(null); // CHAR_OCTET_LENGTH int
  232. a.add(column.getOrdinalPos()); // ORDINAL_POSITION int
  233. a.add("YES"); // IS_NULLABLE String
  234. a.add(null); // SCOPE_CATLOG String
  235. a.add(null); // SCOPE_SCHEMA String
  236. a.add(null); // SCOPE_TABLE String
  237. a.add(null); // SOURCE_DATA_TYPE short
  238. row = a;
  239. cnt++;
  240. return true;
  241. } else {
  242. return false;
  243. }
  244. }
  245. public <T> T getObject(String columnLabel, Class<T> type)
  246. throws SQLException {
  247. // JDK 1.7
  248. throw new SQLException("Method not supported");
  249. }
  250. public <T> T getObject(int columnIndex, Class<T> type)
  251. throws SQLException {
  252. // JDK 1.7
  253. throw new SQLException("Method not supported");
  254. }
  255. };
  256. } catch (Exception e) {
  257. throw new SQLException(e);
  258. }
  259. }
  260. /**
  261. * We sort the output of getColumns to guarantee jdbc compliance.
  262. * First check by table name then by ordinal position
  263. */
  264. private class GetColumnsComparator implements Comparator<JdbcColumn> {
  265. public int compare(JdbcColumn o1, JdbcColumn o2) {
  266. int compareName = o1.getTableName().compareTo(o2.getTableName());
  267. if (compareName==0) {
  268. if (o1.getOrdinalPos() > o2.getOrdinalPos()) {
  269. return 1;
  270. } else if (o1.getOrdinalPos() < o2.getOrdinalPos()) {
  271. return -1;
  272. }
  273. return 0;
  274. } else {
  275. return compareName;
  276. }
  277. }
  278. }
  279. public Connection getConnection() throws SQLException {
  280. throw new SQLException("Method not supported");
  281. }
  282. public ResultSet getCrossReference(String primaryCatalog,
  283. String primarySchema, String primaryTable, String foreignCatalog,
  284. String foreignSchema, String foreignTable) throws SQLException {
  285. throw new SQLException("Method not supported");
  286. }
  287. public int getDatabaseMajorVersion() throws SQLException {
  288. throw new SQLException("Method not supported");
  289. }
  290. public int getDatabaseMinorVersion() throws SQLException {
  291. throw new SQLException("Method not supported");
  292. }
  293. public String getDatabaseProductName() throws SQLException {
  294. return "Hive";
  295. }
  296. public String getDatabaseProductVersion() throws SQLException {
  297. try {
  298. return client.getVersion();
  299. } catch (TException e) {
  300. throw new SQLException(e);
  301. }
  302. }
  303. public int getDefaultTransactionIsolation() throws SQLException {
  304. return Connection.TRANSACTION_NONE;
  305. }
  306. public int getDriverMajorVersion() {
  307. return HiveDriver.getMajorDriverVersion();
  308. }
  309. public int getDriverMinorVersion() {
  310. return HiveDriver.getMinorDriverVersion();
  311. }
  312. public String getDriverName() throws SQLException {
  313. return HiveDriver.fetchManifestAttribute(Attributes.Name.IMPLEMENTATION_TITLE);
  314. }
  315. public String getDriverVersion() throws SQLException {
  316. return HiveDriver.fetchManifestAttribute(Attributes.Name.IMPLEMENTATION_VERSION);
  317. }
  318. public ResultSet getExportedKeys(String catalog, String schema, String table)
  319. throws SQLException {
  320. throw new SQLException("Method not supported");
  321. }
  322. public String getExtraNameCharacters() throws SQLException {
  323. throw new SQLException("Method not supported");
  324. }
  325. public ResultSet getFunctionColumns(String arg0, String arg1, String arg2,
  326. String arg3) throws SQLException {
  327. throw new SQLException("Method not supported");
  328. }
  329. public ResultSet getFunctions(String arg0, String arg1, String arg2)
  330. throws SQLException {
  331. throw new SQLException("Method not supported");
  332. }
  333. public String getIdentifierQuoteString() throws SQLException {
  334. throw new SQLException("Method not supported");
  335. }
  336. public ResultSet getImportedKeys(String catalog, String schema, String table)
  337. throws SQLException {
  338. throw new SQLException("Method not supported");
  339. }
  340. public ResultSet getIndexInfo(String catalog, String schema, String table,
  341. boolean unique, boolean approximate) throws SQLException {
  342. throw new SQLException("Method not supported");
  343. }
  344. public int getJDBCMajorVersion() throws SQLException {
  345. return 3;
  346. }
  347. public int getJDBCMinorVersion() throws SQLException {
  348. return 0;
  349. }
  350. public int getMaxBinaryLiteralLength() throws SQLException {
  351. throw new SQLException("Method not supported");
  352. }
  353. public int getMaxCatalogNameLength() throws SQLException {
  354. throw new SQLException("Method not supported");
  355. }
  356. public int getMaxCharLiteralLength() throws SQLException {
  357. throw new SQLException("Method not supported");
  358. }
  359. /**
  360. * Returns the value of maxColumnNameLength.
  361. *
  362. */
  363. public int getMaxColumnNameLength() throws SQLException {
  364. return maxColumnNameLength;
  365. }
  366. public int getMaxColumnsInGroupBy() throws SQLException {
  367. throw new SQLException("Method not supported");
  368. }
  369. public int getMaxColumnsInIndex() throws SQLException {
  370. throw new SQLException("Method not supported");
  371. }
  372. public int getMaxColumnsInOrderBy() throws SQLException {
  373. throw new SQLException("Method not supported");
  374. }
  375. public int getMaxColumnsInSelect() throws SQLException {
  376. throw new SQLException("Method not supported");
  377. }
  378. public int getMaxColumnsInTable() throws SQLException {
  379. throw new SQLException("Method not supported");
  380. }
  381. public int getMaxConnections() throws SQLException {
  382. throw new SQLException("Method not supported");
  383. }
  384. public int getMaxCursorNameLength() throws SQLException {
  385. throw new SQLException("Method not supported");
  386. }
  387. public int getMaxIndexLength() throws SQLException {
  388. throw new SQLException("Method not supported");
  389. }
  390. public int getMaxProcedureNameLength() throws SQLException {
  391. throw new SQLException("Method not supported");
  392. }
  393. public int getMaxRowSize() throws SQLException {
  394. throw new SQLException("Method not supported");
  395. }
  396. public int getMaxSchemaNameLength() throws SQLException {
  397. throw new SQLException("Method not supported");
  398. }
  399. public int getMaxStatementLength() throws SQLException {
  400. throw new SQLException("Method not supported");
  401. }
  402. public int getMaxStatements() throws SQLException {
  403. throw new SQLException("Method not supported");
  404. }
  405. public int getMaxTableNameLength() throws SQLException {
  406. throw new SQLException("Method not supported");
  407. }
  408. public int getMaxTablesInSelect() throws SQLException {
  409. throw new SQLException("Method not supported");
  410. }
  411. public int getMaxUserNameLength() throws SQLException {
  412. throw new SQLException("Method not supported");
  413. }
  414. public String getNumericFunctions() throws SQLException {
  415. return "";
  416. }
  417. public ResultSet getPrimaryKeys(String catalog, String schema, String table)
  418. throws SQLException {
  419. throw new SQLException("Method not supported");
  420. }
  421. public ResultSet getProcedureColumns(String catalog, String schemaPattern,
  422. String procedureNamePattern, String columnNamePattern)
  423. throws SQLException {
  424. throw new SQLException("Method not supported");
  425. }
  426. public String getProcedureTerm() throws SQLException {
  427. throw new SQLException("Method not supported");
  428. }
  429. public ResultSet getProcedures(String catalog, String schemaPattern,
  430. String procedureNamePattern) throws SQLException {
  431. return null;
  432. }
  433. public int getResultSetHoldability() throws SQLException {
  434. throw new SQLException("Method not supported");
  435. }
  436. public RowIdLifetime getRowIdLifetime() throws SQLException {
  437. throw new SQLException("Method not supported");
  438. }
  439. public String getSQLKeywords() throws SQLException {
  440. throw new SQLException("Method not supported");
  441. }
  442. public int getSQLStateType() throws SQLException {
  443. return DatabaseMetaData.sqlStateSQL99;
  444. }
  445. public String getSchemaTerm() throws SQLException {
  446. return "";
  447. }
  448. public ResultSet getSchemas() throws SQLException {
  449. return getSchemas(null, null);
  450. }
  451. public ResultSet getSchemas(String catalog, String schemaPattern)
  452. throws SQLException {
  453. return new HiveMetaDataResultSet(Arrays.asList("TABLE_SCHEM", "TABLE_CATALOG")
  454. , Arrays.asList("STRING", "STRING"), null) {
  455. public boolean next() throws SQLException {
  456. return false;
  457. }
  458. public <T> T getObject(String columnLabel, Class<T> type)
  459. throws SQLException {
  460. // JDK 1.7
  461. throw new SQLException("Method not supported");
  462. }
  463. public <T> T getObject(int columnIndex, Class<T> type)
  464. throws SQLException {
  465. // JDK 1.7
  466. throw new SQLException("Method not supported");
  467. }
  468. };
  469. }
  470. public String getSearchStringEscape() throws SQLException {
  471. return String.valueOf(SEARCH_STRING_ESCAPE);
  472. }
  473. public String getStringFunctions() throws SQLException {
  474. return "";
  475. }
  476. public ResultSet getSuperTables(String catalog, String schemaPattern,
  477. String tableNamePattern) throws SQLException {
  478. throw new SQLException("Method not supported");
  479. }
  480. public ResultSet getSuperTypes(String catalog, String schemaPattern,
  481. String typeNamePattern) throws SQLException {
  482. throw new SQLException("Method not supported");
  483. }
  484. public String getSystemFunctions() throws SQLException {
  485. return "";
  486. }
  487. public ResultSet getTablePrivileges(String catalog, String schemaPattern,
  488. String tableNamePattern) throws SQLException {
  489. throw new SQLException("Method not supported");
  490. }
  491. public ResultSet getTableTypes() throws SQLException {
  492. final TableType[] tt = TableType.values();
  493. ResultSet result = new HiveMetaDataResultSet<TableType>(
  494. Arrays.asList("TABLE_TYPE")
  495. , Arrays.asList("STRING"), new ArrayList<TableType>(Arrays.asList(tt))) {
  496. private int cnt = 0;
  497. public boolean next() throws SQLException {
  498. if (cnt<data.size()) {
  499. List<Object> a = new ArrayList<Object>(1);
  500. a.add(toJdbcTableType(data.get(cnt).name()));
  501. row = a;
  502. cnt++;
  503. return true;
  504. } else {
  505. return false;
  506. }
  507. }
  508. public <T> T getObject(String columnLabel, Class<T> type)
  509. throws SQLException {
  510. // JDK 1.7
  511. throw new SQLException("Method not supported");
  512. }
  513. public <T> T getObject(int columnIndex, Class<T> type)
  514. throws SQLException {
  515. // JDK 1.7
  516. throw new SQLException("Method not supported");
  517. }
  518. };
  519. return result;
  520. }
  521. public ResultSet getTables(String catalog, String schemaPattern,
  522. String tableNamePattern, String[] types) throws SQLException {
  523. final List<String> tablesstr;
  524. final List<JdbcTable> resultTables = new ArrayList<JdbcTable>();
  525. final String resultCatalog;
  526. if (catalog==null) { // On jdbc the default catalog is null but on hive it's "default"
  527. resultCatalog = "default";
  528. } else {
  529. resultCatalog = catalog;
  530. }
  531. String regtableNamePattern = convertPattern(tableNamePattern);
  532. try {
  533. tablesstr = client.get_tables(resultCatalog, "*");
  534. for (String tablestr: tablesstr) {
  535. if (tablestr.matches(regtableNamePattern)) {
  536. Table tbl = client.get_table(resultCatalog, tablestr);
  537. if (types == null) {
  538. resultTables.add(new JdbcTable(resultCatalog, tbl.getTableName(), tbl.getTableType()
  539. , tbl.getParameters().get("comment")));
  540. } else {
  541. String tableType = toJdbcTableType(tbl.getTableType());
  542. for(String type : types) {
  543. if (type.equalsIgnoreCase(tableType)) {
  544. resultTables.add(new JdbcTable(resultCatalog, tbl.getTableName(), tbl.getTableType()
  545. , tbl.getParameters().get("comment")));
  546. break;
  547. }
  548. }
  549. }
  550. }
  551. }
  552. Collections.sort(resultTables, new GetTablesComparator());
  553. } catch (Exception e) {
  554. throw new SQLException(e);
  555. }
  556. ResultSet result = new HiveMetaDataResultSet<JdbcTable>(
  557. Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS")
  558. , Arrays.asList("STRING", "STRING", "STRING", "STRING", "STRING")
  559. , resultTables) {
  560. private int cnt = 0;
  561. public boolean next() throws SQLException {
  562. if (cnt<data.size()) {
  563. List<Object> a = new ArrayList<Object>(5);
  564. JdbcTable table = data.get(cnt);
  565. a.add(table.getTableCatalog()); // TABLE_CAT String => table catalog (may be null)
  566. a.add(null); // TABLE_SCHEM String => table schema (may be null)
  567. a.add(table.getTableName()); // TABLE_NAME String => table name
  568. try {
  569. a.add(table.getSqlTableType()); // TABLE_TYPE String => "TABLE","VIEW"
  570. } catch (Exception e) {
  571. throw new SQLException(e);
  572. }
  573. a.add(table.getComment()); // REMARKS String => explanatory comment on the table
  574. row = a;
  575. cnt++;
  576. return true;
  577. } else {
  578. return false;
  579. }
  580. }
  581. public <T> T getObject(String columnLabel, Class<T> type)
  582. throws SQLException {
  583. // JDK 1.7
  584. throw new SQLException("Method not supported");
  585. }
  586. public <T> T getObject(int columnIndex, Class<T> type)
  587. throws SQLException {
  588. // JDK 1.7
  589. throw new SQLException("Method not supported");
  590. }
  591. };
  592. return result;
  593. }
  594. /**
  595. * We sort the output of getTables to guarantee jdbc compliance.
  596. * First check by table type then by table name
  597. */
  598. private class GetTablesComparator implements Comparator<JdbcTable> {
  599. public int compare(JdbcTable o1, JdbcTable o2) {
  600. int compareType = o1.getType().compareTo(o2.getType());
  601. if (compareType==0) {
  602. return o1.getTableName().compareTo(o2.getTableName());
  603. } else {
  604. return compareType;
  605. }
  606. }
  607. }
  608. /**
  609. * Translate hive table types into jdbc table types.
  610. * @param hivetabletype
  611. * @return the type of the table
  612. */
  613. public static String toJdbcTableType(String hivetabletype) {
  614. if (hivetabletype==null) {
  615. return null;
  616. } else if (hivetabletype.equals(TableType.MANAGED_TABLE.toString())) {
  617. return "TABLE";
  618. } else if (hivetabletype.equals(TableType.VIRTUAL_VIEW.toString())) {
  619. return "VIEW";
  620. } else if (hivetabletype.equals(TableType.EXTERNAL_TABLE.toString())) {
  621. return "EXTERNAL TABLE";
  622. } else {
  623. return hivetabletype;
  624. }
  625. }
  626. public String getTimeDateFunctions() throws SQLException {
  627. return "";
  628. }
  629. public ResultSet getTypeInfo() throws SQLException {
  630. throw new SQLException("Method not supported");
  631. }
  632. public ResultSet getUDTs(String catalog, String schemaPattern,
  633. String typeNamePattern, int[] types) throws SQLException {
  634. return new HiveMetaDataResultSet(
  635. Arrays.asList("TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "CLASS_NAME", "DATA_TYPE"
  636. , "REMARKS", "BASE_TYPE")
  637. , Arrays.asList("STRING", "STRING", "STRING", "STRING", "INT", "STRING", "INT")
  638. , null) {
  639. public boolean next() throws SQLException {
  640. return false;
  641. }
  642. public <T> T getObject(String columnLabel, Class<T> type)
  643. throws SQLException {
  644. // JDK 1.7
  645. throw new SQLException("Method not supported");
  646. }
  647. public <T> T getObject(int columnIndex, Class<T> type)
  648. throws SQLException {
  649. // JDK 1.7
  650. throw new SQLException("Method not supported");
  651. }
  652. };
  653. }
  654. public String getURL() throws SQLException {
  655. throw new SQLException("Method not supported");
  656. }
  657. public String getUserName() throws SQLException {
  658. throw new SQLException("Method not supported");
  659. }
  660. public ResultSet getVersionColumns(String catalog, String schema, String table)
  661. throws SQLException {
  662. throw new SQLException("Method not supported");
  663. }
  664. public boolean insertsAreDetected(int type) throws SQLException {
  665. throw new SQLException("Method not supported");
  666. }
  667. public boolean isCatalogAtStart() throws SQLException {
  668. throw new SQLException("Method not supported");
  669. }
  670. public boolean isReadOnly() throws SQLException {
  671. throw new SQLException("Method not supported");
  672. }
  673. public boolean locatorsUpdateCopy() throws SQLException {
  674. throw new SQLException("Method not supported");
  675. }
  676. public boolean nullPlusNonNullIsNull() throws SQLException {
  677. throw new SQLException("Method not supported");
  678. }
  679. public boolean nullsAreSortedAtEnd() throws SQLException {
  680. throw new SQLException("Method not supported");
  681. }
  682. public boolean nullsAreSortedAtStart() throws SQLException {
  683. throw new SQLException("Method not supported");
  684. }
  685. public boolean nullsAreSortedHigh() throws SQLException {
  686. throw new SQLException("Method not supported");
  687. }
  688. public boolean nullsAreSortedLow() throws SQLException {
  689. throw new SQLException("Method not supported");
  690. }
  691. public boolean othersDeletesAreVisible(int type) throws SQLException {
  692. throw new SQLException("Method not supported");
  693. }
  694. public boolean othersInsertsAreVisible(int type) throws SQLException {
  695. throw new SQLException("Method not supported");
  696. }
  697. public boolean othersUpdatesAreVisible(int type) throws SQLException {
  698. throw new SQLException("Method not supported");
  699. }
  700. public boolean ownDeletesAreVisible(int type) throws SQLException {
  701. throw new SQLException("Method not supported");
  702. }
  703. public boolean ownInsertsAreVisible(int type) throws SQLException {
  704. throw new SQLException("Method not supported");
  705. }
  706. public boolean ownUpdatesAreVisible(int type) throws SQLException {
  707. throw new SQLException("Method not supported");
  708. }
  709. public boolean storesLowerCaseIdentifiers() throws SQLException {
  710. throw new SQLException("Method not supported");
  711. }
  712. public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
  713. throw new SQLException("Method not supported");
  714. }
  715. public boolean storesMixedCaseIdentifiers() throws SQLException {
  716. throw new SQLException("Method not supported");
  717. }
  718. public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
  719. throw new SQLException("Method not supported");
  720. }
  721. public boolean storesUpperCaseIdentifiers() throws SQLException {
  722. throw new SQLException("Method not supported");
  723. }
  724. public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
  725. throw new SQLException("Method not supported");
  726. }
  727. public boolean supportsANSI92EntryLevelSQL() throws SQLException {
  728. throw new SQLException("Method not supported");
  729. }
  730. public boolean supportsANSI92FullSQL() throws SQLException {
  731. throw new SQLException("Method not supported");
  732. }
  733. public boolean supportsANSI92IntermediateSQL() throws SQLException {
  734. throw new SQLException("Method not supported");
  735. }
  736. public boolean supportsAlterTableWithAddColumn() throws SQLException {
  737. return true;
  738. }
  739. public boolean supportsAlterTableWithDropColumn() throws SQLException {
  740. return false;
  741. }
  742. public boolean supportsBatchUpdates() throws SQLException {
  743. return false;
  744. }
  745. public boolean supportsCatalogsInDataManipulation() throws SQLException {
  746. return false;
  747. }
  748. public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
  749. return false;
  750. }
  751. public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
  752. return false;
  753. }
  754. public boolean supportsCatalogsInProcedureCalls() throws SQLException {
  755. return false;
  756. }
  757. public boolean supportsCatalogsInTableDefinitions() throws SQLException {
  758. return false;
  759. }
  760. public boolean supportsColumnAliasing() throws SQLException {
  761. return true;
  762. }
  763. public boolean supportsConvert() throws SQLException {
  764. throw new SQLException("Method not supported");
  765. }
  766. public boolean supportsConvert(int fromType, int toType) throws SQLException {
  767. throw new SQLException("Method not supported");
  768. }
  769. public boolean supportsCoreSQLGrammar() throws SQLException {
  770. throw new SQLException("Method not supported");
  771. }
  772. public boolean supportsCorrelatedSubqueries() throws SQLException {
  773. throw new SQLException("Method not supported");
  774. }
  775. public boolean supportsDataDefinitionAndDataManipulationTransactions()
  776. throws SQLException {
  777. throw new SQLException("Method not supported");
  778. }
  779. public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
  780. throw new SQLException("Method not supported");
  781. }
  782. public boolean supportsDifferentTableCorrelationNames() throws SQLException {
  783. throw new SQLException("Method not supported");
  784. }
  785. public boolean supportsExpressionsInOrderBy() throws SQLException {
  786. throw new SQLException("Method not supported");
  787. }
  788. public boolean supportsExtendedSQLGrammar() throws SQLException {
  789. throw new SQLException("Method not supported");
  790. }
  791. public boolean supportsFullOuterJoins() throws SQLException {
  792. throw new SQLException("Method not supported");
  793. }
  794. public boolean supportsGetGeneratedKeys() throws SQLException {
  795. throw new SQLException("Method not supported");
  796. }
  797. public boolean supportsGroupBy() throws SQLException {
  798. return true;
  799. }
  800. public boolean supportsGroupByBeyondSelect() throws SQLException {
  801. throw new SQLException("Method not supported");
  802. }
  803. public boolean supportsGroupByUnrelated() throws SQLException {
  804. throw new SQLException("Method not supported");
  805. }
  806. public boolean supportsIntegrityEnhancementFacility() throws SQLException {
  807. throw new SQLException("Method not supported");
  808. }
  809. public boolean supportsLikeEscapeClause() throws SQLException {
  810. throw new SQLException("Method not supported");
  811. }
  812. public boolean supportsLimitedOuterJoins() throws SQLException {
  813. throw new SQLException("Method not supported");
  814. }
  815. public boolean supportsMinimumSQLGrammar() throws SQLException {
  816. throw new SQLException("Method not supported");
  817. }
  818. public boolean supportsMixedCaseIdentifiers() throws SQLException {
  819. throw new SQLException("Method not supported");
  820. }
  821. public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
  822. throw new SQLException("Method not supported");
  823. }
  824. public boolean supportsMultipleOpenResults() throws SQLException {
  825. throw new SQLException("Method not supported");
  826. }
  827. public boolean supportsMultipleResultSets() throws SQLException {
  828. return false;
  829. }
  830. public boolean supportsMultipleTransactions() throws SQLException {
  831. throw new SQLException("Method not supported");
  832. }
  833. public boolean supportsNamedParameters() throws SQLException {
  834. throw new SQLException("Method not supported");
  835. }
  836. public boolean supportsNonNullableColumns() throws SQLException {
  837. return false;
  838. }
  839. public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
  840. throw new SQLException("Method not supported");
  841. }
  842. public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
  843. throw new SQLException("Method not supported");
  844. }
  845. public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
  846. throw new SQLException("Method not supported");
  847. }
  848. public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
  849. throw new SQLException("Method not supported");
  850. }
  851. public boolean supportsOrderByUnrelated() throws SQLException {
  852. throw new SQLException("Method not supported");
  853. }
  854. public boolean supportsOuterJoins() throws SQLException {
  855. return true;
  856. }
  857. public boolean supportsPositionedDelete() throws SQLException {
  858. return false;
  859. }
  860. public boolean supportsPositionedUpdate() throws SQLException {
  861. return false;
  862. }
  863. public boolean supportsResultSetConcurrency(int type, int concurrency)
  864. throws SQLException {
  865. throw new SQLException("Method not supported");
  866. }
  867. public boolean supportsResultSetHoldability(int holdability)
  868. throws SQLException {
  869. return false;
  870. }
  871. public boolean supportsResultSetType(int type) throws SQLException {
  872. return true;
  873. }
  874. public boolean supportsSavepoints() throws SQLException {
  875. return false;
  876. }
  877. public boolean supportsSchemasInDataManipulation() throws SQLException {
  878. return false;
  879. }
  880. public boolean supportsSchemasInIndexDefinitions() throws SQLException {
  881. return false;
  882. }
  883. public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
  884. return false;
  885. }
  886. public boolean supportsSchemasInProcedureCalls() throws SQLException {
  887. return false;
  888. }
  889. public boolean supportsSchemasInTableDefinitions() throws SQLException {
  890. return false;
  891. }
  892. public boolean supportsSelectForUpdate() throws SQLException {
  893. return false;
  894. }
  895. public boolean supportsStatementPooling() throws SQLException {
  896. throw new SQLException("Method not supported");
  897. }
  898. public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
  899. throw new SQLException("Method not supported");
  900. }
  901. public boolean supportsStoredProcedures() throws SQLException {
  902. return false;
  903. }
  904. public boolean supportsSubqueriesInComparisons() throws SQLException {
  905. throw new SQLException("Method not supported");
  906. }
  907. public boolean supportsSubqueriesInExists() throws SQLException {
  908. throw new SQLException("Method not supported");
  909. }
  910. public boolean supportsSubqueriesInIns() throws SQLException {
  911. throw new SQLException("Method not supported");
  912. }
  913. public boolean supportsSubqueriesInQuantifieds() throws SQLException {
  914. throw new SQLException("Method not supported");
  915. }
  916. public boolean supportsTableCorrelationNames() throws SQLException {
  917. throw new SQLException("Method not supported");
  918. }
  919. public boolean supportsTransactionIsolationLevel(int level)
  920. throws SQLException {
  921. throw new SQLException("Method not supported");
  922. }
  923. public boolean supportsTransactions() throws SQLException {
  924. return false;
  925. }
  926. public boolean supportsUnion() throws SQLException {
  927. throw new SQLException("Method not supported");
  928. }
  929. public boolean supportsUnionAll() throws SQLException {
  930. throw new SQLException("Method not supported");
  931. }
  932. public boolean updatesAreDetected(int type) throws SQLException {
  933. throw new SQLException("Method not supported");
  934. }
  935. public boolean usesLocalFilePerTable() throws SQLException {
  936. throw new SQLException("Method not supported");
  937. }
  938. public boolean usesLocalFiles() throws SQLException {
  939. throw new SQLException("Method not supported");
  940. }
  941. public boolean isWrapperFor(Class<?> iface) throws SQLException {
  942. throw new SQLException("Method not supported");
  943. }
  944. public <T> T unwrap(Class<T> iface) throws SQLException {
  945. throw new SQLException("Method not supported");
  946. }
  947. public static void main(String[] args) throws SQLException {
  948. HiveDatabaseMetaData meta = new HiveDatabaseMetaData(null);
  949. System.out.println("DriverName: " + meta.getDriverName());
  950. System.out.println("DriverVersion: " + meta.getDriverVersion());
  951. }
  952. }