Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MetadataOp.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.service;
16 
17 import java.sql.DatabaseMetaData;
18 import java.util.HashSet;
19 import java.util.List;
20 import java.util.Set;
21 
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 
37 import com.cloudera.impala.thrift.TColumn;
38 import com.cloudera.impala.thrift.TColumnValue;
39 import com.cloudera.impala.thrift.TResultRow;
40 import com.cloudera.impala.thrift.TResultSet;
41 import com.cloudera.impala.thrift.TResultSetMetadata;
43 import com.google.common.collect.Lists;
44 
50 public class MetadataOp {
51  private static final Logger LOG = LoggerFactory.getLogger(MetadataOp.class);
52 
53  // Static column values
54  private static final TColumnValue NULL_COL_VAL = new TColumnValue();
55  private static final TColumnValue EMPTY_COL_VAL = createTColumnValue("");
56  private static final TColumnValue TABLE_TYPE_COL_VAL = createTColumnValue("TABLE");
57 
58  // Result set schema for each of the metadata operations.
59  private final static TResultSetMetadata GET_CATALOGS_MD = new TResultSetMetadata();
60  private final static TResultSetMetadata GET_COLUMNS_MD = new TResultSetMetadata();
61  private final static TResultSetMetadata GET_SCHEMAS_MD = new TResultSetMetadata();
62  private final static TResultSetMetadata GET_TABLES_MD = new TResultSetMetadata();
63  private static final TResultSetMetadata GET_TYPEINFO_MD = new TResultSetMetadata();
64  private static final TResultSetMetadata GET_TABLE_TYPES_MD = new TResultSetMetadata();
65  private static final TResultSetMetadata GET_FUNCTIONS_MD = new TResultSetMetadata();
66 
67  // GetTypeInfo contains all primitive types supported by Impala.
68  private static final List<TResultRow> GET_TYPEINFO_RESULTS = Lists.newArrayList();
69 
70  // GetTableTypes only returns a single value: "TABLE".
71  private static final List<TResultRow> GET_TABLE_TYPES_RESULTS = Lists.newArrayList();
72 
73  // Initialize result set schemas and static result set
74  static {
78  }
79 
83  private static void initialzeResultSetSchemas() {
84  GET_CATALOGS_MD.addToColumns(new TColumn("TABLE_CAT", Type.STRING.toThrift()));
85 
86  GET_COLUMNS_MD.addToColumns(
87  new TColumn("TABLE_CAT", Type.STRING.toThrift()));
88  GET_COLUMNS_MD.addToColumns(
89  new TColumn("TABLE_MD", Type.STRING.toThrift()));
90  GET_COLUMNS_MD.addToColumns(
91  new TColumn("TABLE_NAME", Type.STRING.toThrift()));
92  GET_COLUMNS_MD.addToColumns(
93  new TColumn("COLUMN_NAME", Type.STRING.toThrift()));
94  GET_COLUMNS_MD.addToColumns(
95  new TColumn("DATA_TYPE", Type.INT.toThrift()));
96  GET_COLUMNS_MD.addToColumns(
97  new TColumn("TYPE_NAME", Type.STRING.toThrift()));
98  GET_COLUMNS_MD.addToColumns(
99  new TColumn("COLUMN_SIZE", Type.INT.toThrift()));
100  GET_COLUMNS_MD.addToColumns(
101  new TColumn("BUFFER_LENGTH", Type.INT.toThrift()));
102  GET_COLUMNS_MD.addToColumns(
103  new TColumn("DECIMAL_DIGITS", Type.INT.toThrift()));
104  GET_COLUMNS_MD.addToColumns(
105  new TColumn("NUM_PREC_RADIX", Type.INT.toThrift()));
106  GET_COLUMNS_MD.addToColumns(
107  new TColumn("NULLABLE", Type.INT.toThrift()));
108  GET_COLUMNS_MD.addToColumns(
109  new TColumn("REMARKS", Type.STRING.toThrift()));
110  GET_COLUMNS_MD.addToColumns(
111  new TColumn("COLUMN_DEF", Type.STRING.toThrift()));
112  GET_COLUMNS_MD.addToColumns(
113  new TColumn("SQL_DATA_TYPE", Type.INT.toThrift()));
114  GET_COLUMNS_MD.addToColumns(
115  new TColumn("SQL_DATETIME_SUB", Type.INT.toThrift()));
116  GET_COLUMNS_MD.addToColumns(
117  new TColumn("CHAR_OCTET_LENGTH", Type.INT.toThrift()));
118  GET_COLUMNS_MD.addToColumns(
119  new TColumn("ORDINAL_POSITION", Type.INT.toThrift()));
120  GET_COLUMNS_MD.addToColumns(
121  new TColumn("IS_NULLABLE", Type.STRING.toThrift()));
122  GET_COLUMNS_MD.addToColumns(
123  new TColumn("SCOPE_CATALOG", Type.STRING.toThrift()));
124  GET_COLUMNS_MD.addToColumns(
125  new TColumn("SCOPE_SCHEMA", Type.STRING.toThrift()));
126  GET_COLUMNS_MD.addToColumns(
127  new TColumn("SCOPE_TABLE", Type.STRING.toThrift()));
128  GET_COLUMNS_MD.addToColumns(
129  new TColumn("SOURCE_DATA_TYPE", Type.SMALLINT.toThrift()));
130  GET_COLUMNS_MD.addToColumns(
131  new TColumn("IS_AUTO_INCREMENT", Type.STRING.toThrift()));
132 
133  GET_SCHEMAS_MD.addToColumns(
134  new TColumn("TABLE_SCHEM", Type.STRING.toThrift()));
135  GET_SCHEMAS_MD.addToColumns(
136  new TColumn("TABLE_CATALOG", Type.STRING.toThrift()));
137 
138  GET_TABLES_MD.addToColumns(
139  new TColumn("TABLE_CAT", Type.STRING.toThrift()));
140  GET_TABLES_MD.addToColumns(
141  new TColumn("TABLE_SCHEM", Type.STRING.toThrift()));
142  GET_TABLES_MD.addToColumns(
143  new TColumn("TABLE_NAME", Type.STRING.toThrift()));
144  GET_TABLES_MD.addToColumns(
145  new TColumn("TABLE_TYPE", Type.STRING.toThrift()));
146  GET_TABLES_MD.addToColumns(
147  new TColumn("REMARKS", Type.STRING.toThrift()));
148 
149  GET_TYPEINFO_MD.addToColumns(
150  new TColumn("TYPE_NAME", Type.STRING.toThrift()));
151  GET_TYPEINFO_MD.addToColumns(
152  new TColumn("DATA_TYPE", Type.INT.toThrift()));
153  GET_TYPEINFO_MD.addToColumns(
154  new TColumn("PRECISION", Type.INT.toThrift()));
155  GET_TYPEINFO_MD.addToColumns(
156  new TColumn("LITERAL_PREFIX", Type.STRING.toThrift()));
157  GET_TYPEINFO_MD.addToColumns(
158  new TColumn("LITERAL_SUFFIX", Type.STRING.toThrift()));
159  GET_TYPEINFO_MD.addToColumns(
160  new TColumn("CREATE_PARAMS", Type.STRING.toThrift()));
161  GET_TYPEINFO_MD.addToColumns(
162  new TColumn("NULLABLE", Type.INT.toThrift()));
163  GET_TYPEINFO_MD.addToColumns(
164  new TColumn("CASE_SENSITIVE", Type.BOOLEAN.toThrift()));
165  GET_TYPEINFO_MD.addToColumns(
166  new TColumn("SEARCHABLE", Type.SMALLINT.toThrift()));
167  GET_TYPEINFO_MD.addToColumns(
168  new TColumn("UNSIGNED_ATTRIBUTE", Type.BOOLEAN.toThrift()));
169  GET_TYPEINFO_MD.addToColumns(
170  new TColumn("FIXED_PREC_SCALE", Type.BOOLEAN.toThrift()));
171  GET_TYPEINFO_MD.addToColumns(
172  new TColumn("AUTO_INCREMENT", Type.BOOLEAN.toThrift()));
173  GET_TYPEINFO_MD.addToColumns(
174  new TColumn("LOCAL_TYPE_NAME", Type.STRING.toThrift()));
175  GET_TYPEINFO_MD.addToColumns(
176  new TColumn("MINIMUM_SCALE", Type.SMALLINT.toThrift()));
177  GET_TYPEINFO_MD.addToColumns(
178  new TColumn("MAXIMUM_SCALE", Type.SMALLINT.toThrift()));
179  GET_TYPEINFO_MD.addToColumns(
180  new TColumn("SQL_DATA_TYPE", Type.INT.toThrift()));
181  GET_TYPEINFO_MD.addToColumns(
182  new TColumn("SQL_DATETIME_SUB", Type.INT.toThrift()));
183  GET_TYPEINFO_MD.addToColumns(
184  new TColumn("NUM_PREC_RADIX", Type.INT.toThrift()));
185 
186  GET_TABLE_TYPES_MD.addToColumns(
187  new TColumn("TABLE_TYPE", Type.STRING.toThrift()));
188 
189  GET_FUNCTIONS_MD.addToColumns(
190  new TColumn("FUNCTION_CAT", Type.STRING.toThrift()));
191  GET_FUNCTIONS_MD.addToColumns(
192  new TColumn("FUNCTION_SCHEM", Type.STRING.toThrift()));
193  GET_FUNCTIONS_MD.addToColumns(
194  new TColumn("FUNCTION_NAME", Type.STRING.toThrift()));
195  GET_FUNCTIONS_MD.addToColumns(
196  new TColumn("REMARKS", Type.STRING.toThrift()));
197  GET_FUNCTIONS_MD.addToColumns(
198  new TColumn("FUNCTION_TYPE", Type.INT.toThrift()));
199  GET_FUNCTIONS_MD.addToColumns(
200  new TColumn("SPECIFIC_NAME", Type.STRING.toThrift()));
201  }
202 
207  private static class DbsMetadata {
208  // the list of database
209  public List<String> dbs = Lists.newArrayList();
210 
211  // tableNames[i] are the tables within dbs[i]
212  public List<List<String>> tableNames = Lists.newArrayList();
213 
214  // columns[i][j] are the columns of tableNames[j] in dbs[i].
215  // If the table is missing (not yet loaded) its column list will be empty.
216  public List<List<List<Column>>> columns = Lists.newArrayList();
217 
218  // functions[i] are the functions within dbs[i]
219  public List<List<Function>> functions = Lists.newArrayList();
220 
221  // Set of tables that are missing (not yet loaded).
222  public Set<TableName> missingTbls = new HashSet<TableName>();
223  }
224 
244  private static DbsMetadata getDbsMetadata(Frontend fe, String catalogName,
245  String schemaName, String tableName, String columnName, String functionName,
246  User user) throws ImpalaException {
247  DbsMetadata result = new DbsMetadata();
248 
249  // Hive does not have a catalog concept. Returns nothing if the request specifies an
250  // non-empty catalog pattern.
251  if (!isEmptyPattern(catalogName)) {
252  return result;
253  }
254 
255  // Creates the schema, table, column and function search patterns
256  PatternMatcher schemaPattern = PatternMatcher.createJdbcPatternMatcher(schemaName);
257  PatternMatcher tablePattern = PatternMatcher.createJdbcPatternMatcher(tableName);
258  PatternMatcher columnPattern = PatternMatcher.createJdbcPatternMatcher(columnName);
259  PatternMatcher fnPattern = PatternMatcher.createJdbcPatternMatcher(functionName);
260 
261  ImpaladCatalog catalog = fe.getCatalog();
262  for (String dbName: fe.getDbNames(null, user)) {
263  if (!schemaPattern.matches(dbName)) continue;
264 
265  Db db = catalog.getDb(dbName);
266  if (db == null) continue;
267 
268  if (functionName != null) {
269  // Get function metadata
270  List<Function> fns = db.getFunctions(null, fnPattern);
271  result.functions.add(fns);
272  } else {
273  // Get table metadata
274  List<String> tableList = Lists.newArrayList();
275  List<List<Column>> tablesColumnsList = Lists.newArrayList();
276  for (String tabName: fe.getTableNames(db.getName(), "*", user)) {
277  if (!tablePattern.matches(tabName)) continue;
278  tableList.add(tabName);
279  List<Column> columns = Lists.newArrayList();
280 
281  Table table = null;
282  try {
283  table = catalog.getTable(dbName, tabName);
284  } catch (TableLoadingException e) {
285  // Ignore exception (this table will be skipped).
286  }
287  if (table == null) continue;
288 
289  // If the table is not yet loaded, the columns will be unknown. Add it
290  // to the set of missing tables.
291  if (!table.isLoaded()) {
292  result.missingTbls.add(new TableName(dbName, tabName));
293  } else {
294  for (Column column: table.getColumnsInHiveOrder()) {
295  String colName = column.getName();
296  if (!columnPattern.matches(colName)) continue;
297  columns.add(column);
298  }
299  }
300  tablesColumnsList.add(columns);
301  }
302  result.dbs.add(dbName);
303  result.tableNames.add(tableList);
304  result.columns.add(tablesColumnsList);
305  }
306  }
307  return result;
308  }
309 
314  public static TResultSet getCatalogs() {
316  }
317 
330  public static TResultSet getColumns(Frontend fe,
331  String catalogName, String schemaName, String tableName, String columnName,
332  User user)
333  throws ImpalaException {
334  TResultSet result = createEmptyResultSet(GET_COLUMNS_MD);
335 
336  // Get the list of schemas, tables, and columns that satisfy the search conditions.
337  DbsMetadata dbsMetadata = null;
338  while (dbsMetadata == null || !dbsMetadata.missingTbls.isEmpty()) {
339  dbsMetadata = getDbsMetadata(fe, catalogName,
340  schemaName, tableName, columnName, null, user);
341  if (!fe.requestTblLoadAndWait(dbsMetadata.missingTbls)) {
342  LOG.info("Timed out waiting for missing tables. Load request will be retried.");
343  }
344  }
345 
346  for (int i = 0; i < dbsMetadata.dbs.size(); ++i) {
347  String dbName = dbsMetadata.dbs.get(i);
348  for (int j = 0; j < dbsMetadata.tableNames.get(i).size(); ++j) {
349  String tabName = dbsMetadata.tableNames.get(i).get(j);
350  for (int k = 0; k < dbsMetadata.columns.get(i).get(j).size(); ++k) {
351  Column column = dbsMetadata.columns.get(i).get(j).get(k);
352  Type colType = column.getType();
353  TResultRow row = new TResultRow();
354  row.colVals = Lists.newArrayList();
355  row.colVals.add(NULL_COL_VAL); // TABLE_CAT
356  row.colVals.add(createTColumnValue(dbName)); // TABLE_SCHEM
357  row.colVals.add(createTColumnValue(tabName)); // TABLE_NAME
358  row.colVals.add(createTColumnValue(column.getName())); // COLUMN_NAME
359  row.colVals.add(createTColumnValue(colType.getJavaSqlType())); // DATA_TYPE
360  row.colVals.add(
361  createTColumnValue(colType.getPrimitiveType().name())); // TYPE_NAME
362  row.colVals.add(createTColumnValue(colType.getColumnSize())); // COLUMN_SIZE
363  row.colVals.add(NULL_COL_VAL); // BUFFER_LENGTH, unused
364  // DECIMAL_DIGITS
365  row.colVals.add(createTColumnValue(colType.getDecimalDigits()));
366  // NUM_PREC_RADIX
367  row.colVals.add(createTColumnValue(colType.getNumPrecRadix()));
368  // NULLABLE
369  row.colVals.add(createTColumnValue(DatabaseMetaData.columnNullable));
370  row.colVals.add(NULL_COL_VAL); // REMARKS
371  row.colVals.add(NULL_COL_VAL); // COLUMN_DEF
372  row.colVals.add(NULL_COL_VAL); // SQL_DATA_TYPE
373  row.colVals.add(NULL_COL_VAL); // SQL_DATETIME_SUB
374  row.colVals.add(NULL_COL_VAL); // CHAR_OCTET_LENGTH
375  // ORDINAL_POSITION starts from 1
376  row.colVals.add(createTColumnValue(column.getPosition() + 1));
377  row.colVals.add(createTColumnValue("YES")); // IS_NULLABLE
378  row.colVals.add(NULL_COL_VAL); // SCOPE_CATALOG
379  row.colVals.add(NULL_COL_VAL); // SCOPE_SCHEMA
380  row.colVals.add(NULL_COL_VAL); // SCOPE_TABLE
381  row.colVals.add(NULL_COL_VAL); // SOURCE_DATA_TYPE
382  row.colVals.add(createTColumnValue("NO")); // IS_AUTO_INCREMENT
383  result.rows.add(row);
384  }
385  }
386  }
387  LOG.debug("Returning " + result.rows.size() + " table columns");
388  return result;
389  }
390 
397  public static TResultSet getSchemas(Frontend fe,
398  String catalogName, String schemaName, User user) throws ImpalaException {
399  TResultSet result = createEmptyResultSet(GET_SCHEMAS_MD);
400 
401  // Get the list of schemas that satisfy the search condition.
402  DbsMetadata dbsMetadata = getDbsMetadata(fe, catalogName,
403  schemaName, null, null, null, user);
404 
405  for (int i = 0; i < dbsMetadata.dbs.size(); ++i) {
406  String dbName = dbsMetadata.dbs.get(i);
407  TResultRow row = new TResultRow();
408  row.colVals = Lists.newArrayList();
409  row.colVals.add(createTColumnValue(dbName)); // TABLE_SCHEM
410  row.colVals.add(EMPTY_COL_VAL); // default Hive catalog is an empty string.
411  result.rows.add(row);
412  }
413 
414  LOG.debug("Returning " + result.rows.size() + " schemas");
415  return result;
416  }
417 
425  public static TResultSet getTables(Frontend fe, String catalogName,
426  String schemaName, String tableName, List<String> tableTypes, User user)
427  throws ImpalaException{
428  TResultSet result = createEmptyResultSet(GET_TABLES_MD);
429 
430  // Impala catalog only contains TABLE. Returns an empty set if the search does not
431  // include TABLE.
432  if (tableTypes != null && !tableTypes.isEmpty()) {
433  boolean hasTableType = false;
434  for (String tableType: tableTypes) {
435  if (tableType.toLowerCase().equals("table")) {
436  hasTableType = true;
437  break;
438  }
439  }
440  if (!hasTableType) {
441  return result;
442  }
443  }
444 
445  // Get the list of schemas, tables that satisfy the search conditions.
446  DbsMetadata dbsMetadata = getDbsMetadata(fe, catalogName,
447  schemaName, tableName, null, null, user);
448 
449  for (int i = 0; i < dbsMetadata.dbs.size(); ++i) {
450  String dbName = dbsMetadata.dbs.get(i);
451  for (int j = 0; j < dbsMetadata.tableNames.get(i).size(); ++j) {
452  String tabName = dbsMetadata.tableNames.get(i).get(j);
453  TResultRow row = new TResultRow();
454  row.colVals = Lists.newArrayList();
455  row.colVals.add(EMPTY_COL_VAL);
456  row.colVals.add(createTColumnValue(dbName));
457  row.colVals.add(createTColumnValue(tabName));
458  row.colVals.add(TABLE_TYPE_COL_VAL);
459  // TODO: Return table comments when it is available in the Impala catalog.
460  row.colVals.add(EMPTY_COL_VAL);
461  result.rows.add(row);
462  }
463  }
464  LOG.debug("Returning " + result.rows.size() + " tables");
465  return result;
466  }
467 
471  public static TResultSet getTypeInfo() {
472  TResultSet result = createEmptyResultSet(GET_TYPEINFO_MD);
473  result.rows = GET_TYPEINFO_RESULTS;
474  return result;
475  }
476 
480  public static TResultSet getTableTypes() {
481  TResultSet result = createEmptyResultSet(GET_TABLE_TYPES_MD);
482  result.rows = GET_TABLE_TYPES_RESULTS;
483  return result;
484  }
485 
489  private static TResultRow createFunctionResultRow(Function fn) {
490  TResultRow row = new TResultRow();
491  row.colVals = Lists.newArrayList();
492  row.colVals.add(NULL_COL_VAL); // FUNCTION_CAT
493  row.colVals.add(createTColumnValue(fn.dbName())); // FUNCTION_SCHEM
494  row.colVals.add(createTColumnValue(fn.functionName())); // FUNCTION_NAME
495  row.colVals.add(EMPTY_COL_VAL); // REMARKS
496  // FUNCTION_TYPE
497  row.colVals.add(createTColumnValue(DatabaseMetaData.functionNoTable));
498  row.colVals.add(createTColumnValue(fn.signatureString())); // SPECIFIC_NAME
499  return row;
500  }
501 
508  public static TResultSet getFunctions(Frontend fe,
509  String catalogName, String schemaName, String functionName,
510  User user) throws ImpalaException {
511  TResultSet result = createEmptyResultSet(GET_FUNCTIONS_MD);
512 
513  // Impala's built-in functions do not have a catalog name or schema name.
514  if (!isEmptyPattern(catalogName) || !isEmptyPattern(schemaName)) {
515  return result;
516  }
517 
518  DbsMetadata dbsMetadata = getDbsMetadata(fe, catalogName,
519  schemaName, null, null, functionName, user);
520  for (List<Function> fns: dbsMetadata.functions) {
521  for (Function fn: fns) {
522  result.rows.add(createFunctionResultRow(fn));
523  }
524  }
525 
526  return result;
527  }
528 
532  private static void createGetTypeInfoResults() {
533  for (PrimitiveType ptype: PrimitiveType.values()) {
534  if (ptype.equals(PrimitiveType.INVALID_TYPE) ||
535  ptype.equals(PrimitiveType.DATE) ||
536  ptype.equals(PrimitiveType.DATETIME) ||
537  ptype.equals(PrimitiveType.DECIMAL) ||
538  ptype.equals(PrimitiveType.CHAR) ||
539  ptype.equals(PrimitiveType.VARCHAR)) {
540  continue;
541  }
542  Type type = ScalarType.createType(ptype);
543  TResultRow row = new TResultRow();
544  row.colVals = Lists.newArrayList();
545  row.colVals.add(createTColumnValue(ptype.name())); // TYPE_NAME
546  row.colVals.add(createTColumnValue(type.getJavaSqlType())); // DATA_TYPE
547  row.colVals.add(createTColumnValue(type.getPrecision())); // PRECISION
548  row.colVals.add(NULL_COL_VAL); // LITERAL_PREFIX
549  row.colVals.add(NULL_COL_VAL); // LITERAL_SUFFIX
550  row.colVals.add(NULL_COL_VAL); // CREATE_PARAMS
551  row.colVals.add(createTColumnValue(DatabaseMetaData.typeNullable)); // NULLABLE
552  row.colVals.add(createTColumnValue(type.isStringType())); // CASE_SENSITIVE
553  row.colVals.add(createTColumnValue(DatabaseMetaData.typeSearchable)); // SEARCHABLE
554  row.colVals.add(createTColumnValue(!type.isNumericType())); // UNSIGNED_ATTRIBUTE
555  row.colVals.add(createTColumnValue(false)); // FIXED_PREC_SCALE
556  row.colVals.add(createTColumnValue(false)); // AUTO_INCREMENT
557  row.colVals.add(NULL_COL_VAL); // LOCAL_TYPE_NAME
558  row.colVals.add(createTColumnValue(0)); // MINIMUM_SCALE
559  row.colVals.add(createTColumnValue(0)); // MAXIMUM_SCALE
560  row.colVals.add(NULL_COL_VAL); // SQL_DATA_TYPE
561  row.colVals.add(NULL_COL_VAL); // SQL_DATETIME_SUB
562  row.colVals.add(createTColumnValue(type.getNumPrecRadix())); // NUM_PREC_RADIX
563  GET_TYPEINFO_RESULTS.add(row);
564  }
565  }
566 
570  private static void createGetTableTypesResults() {
571  TResultRow row = new TResultRow();
572  row.colVals = Lists.newArrayList();
573  row.colVals.add(createTColumnValue("TABLE"));
574  GET_TABLE_TYPES_RESULTS.add(row);
575  }
576 
581  private static TResultSet createEmptyResultSet(TResultSetMetadata metadata) {
582  TResultSet result = new TResultSet();
583  result.rows = Lists.newArrayList();
584  result.schema = metadata;
585  return result;
586  }
587 
588  // Helper methods to create TColumnValue
589  public static TColumnValue createTColumnValue(String val) {
590  TColumnValue colVal = new TColumnValue();
591  if (val != null) {
592  colVal.setString_val(val);
593  }
594  return colVal;
595  }
596 
597  public static TColumnValue createTColumnValue(Integer val) {
598  TColumnValue colVal = new TColumnValue();
599  if (val != null) {
600  colVal.setInt_val(val.intValue());
601  }
602  return colVal;
603  }
604 
605  public static TColumnValue createTColumnValue(Boolean val) {
606  TColumnValue colVal = new TColumnValue();
607  if (val != null) {
608  colVal.setBool_val(val);
609  }
610  return colVal;
611  }
612 
616  public static boolean isEmptyPattern(final String pattern) {
617  return (pattern == null) || pattern.isEmpty() ||
618  (pattern.length() == 1 && pattern.equals("%"));
619  }
620 }
static final TResultSetMetadata GET_TYPEINFO_MD
Definition: MetadataOp.java:63
static final TResultSetMetadata GET_CATALOGS_MD
Definition: MetadataOp.java:59
static final List< TResultRow > GET_TABLE_TYPES_RESULTS
Definition: MetadataOp.java:71
static TColumnValue createTColumnValue(String val)
static final ScalarType STRING
Definition: Type.java:53
static final ScalarType BOOLEAN
Definition: Type.java:46
static TResultSet getTables(Frontend fe, String catalogName, String schemaName, String tableName, List< String > tableTypes, User user)
static final TColumnValue NULL_COL_VAL
Definition: MetadataOp.java:54
static TResultSet getSchemas(Frontend fe, String catalogName, String schemaName, User user)
static final ScalarType SMALLINT
Definition: Type.java:48
static TColumnValue createTColumnValue(Boolean val)
static final TColumnValue TABLE_TYPE_COL_VAL
Definition: MetadataOp.java:56
PrimitiveType
Definition: types.h:27
static final TResultSetMetadata GET_TABLES_MD
Definition: MetadataOp.java:62
static TResultSet createEmptyResultSet(TResultSetMetadata metadata)
static final TResultSetMetadata GET_COLUMNS_MD
Definition: MetadataOp.java:60
static TResultSet getColumns(Frontend fe, String catalogName, String schemaName, String tableName, String columnName, User user)
static final ScalarType INT
Definition: Type.java:49
static final TResultSetMetadata GET_TABLE_TYPES_MD
Definition: MetadataOp.java:64
static TResultSet getFunctions(Frontend fe, String catalogName, String schemaName, String functionName, User user)
static final TColumnValue EMPTY_COL_VAL
Definition: MetadataOp.java:55
static final TResultSetMetadata GET_FUNCTIONS_MD
Definition: MetadataOp.java:65
void toThrift(TColumnType container)
static boolean isEmptyPattern(final String pattern)
static final TResultSetMetadata GET_SCHEMAS_MD
Definition: MetadataOp.java:61
static DbsMetadata getDbsMetadata(Frontend fe, String catalogName, String schemaName, String tableName, String columnName, String functionName, User user)
static TColumnValue createTColumnValue(Integer val)
static final List< TResultRow > GET_TYPEINFO_RESULTS
Definition: MetadataOp.java:68
static TResultRow createFunctionResultRow(Function fn)