3 package com.cloudera.impala.service;
5 import static org.junit.Assert.assertEquals;
6 import static org.junit.Assert.assertTrue;
7 import static org.junit.Assert.fail;
12 import org.apache.hive.service.cli.thrift.TGetCatalogsReq;
13 import org.apache.hive.service.cli.thrift.TGetColumnsReq;
14 import org.apache.hive.service.cli.thrift.TGetFunctionsReq;
15 import org.apache.hive.service.cli.thrift.TGetInfoReq;
16 import org.apache.hive.service.cli.thrift.TGetSchemasReq;
17 import org.apache.hive.service.cli.thrift.TGetTablesReq;
26 import com.cloudera.impala.thrift.TMetadataOpRequest;
27 import com.cloudera.impala.thrift.TMetadataOpcode;
28 import com.cloudera.impala.thrift.TQueryCtx;
29 import com.cloudera.impala.thrift.TResultRow;
30 import com.cloudera.impala.thrift.TResultSet;
31 import com.google.common.collect.Lists;
32 import com.google.common.collect.Sets;
49 TQueryCtx queryCtx = TestUtils.createQueryContext(
"default",
"fake_user");
52 queryCtx.request.setStmt(
"select 1");
53 fe.createExecRequest(queryCtx,
new StringBuilder());
56 queryCtx.request.setStmt(
"show tables");
58 fe.createExecRequest(queryCtx,
new StringBuilder());
59 fail(
"Expected failure to due uninitialized catalog.");
61 assertEquals(
"This Impala daemon is not ready to accept user requests. " +
62 "Status: Waiting for catalog update from the StateStore.", e.getMessage());
69 TMetadataOpRequest getInfoReq =
new TMetadataOpRequest();
70 getInfoReq.opcode = TMetadataOpcode.GET_TYPE_INFO;
71 getInfoReq.get_info_req =
new TGetInfoReq();
74 assertEquals(18, resp.schema.columns.size());
75 assertEquals(18, resp.rows.get(0).colVals.size());
79 assertEquals(
PrimitiveType.values().length - 6, resp.rows.size());
85 TMetadataOpRequest req =
new TMetadataOpRequest();
86 req.opcode = TMetadataOpcode.GET_SCHEMAS;
87 req.get_schemas_req =
new TGetSchemasReq();
88 req.get_schemas_req.setSchemaName(
"default%");
91 assertEquals(2, resp.schema.columns.size());
92 assertEquals(2, resp.rows.get(0).colVals.size());
93 assertEquals(1, resp.rows.size());
94 assertEquals(
"default", resp.rows.get(0).colVals.get(0).string_val.toLowerCase());
100 TMetadataOpRequest req =
new TMetadataOpRequest();
101 req.opcode = TMetadataOpcode.GET_TABLES;
102 req.get_tables_req =
new TGetTablesReq();
103 req.get_tables_req.setSchemaName(
"functional");
104 req.get_tables_req.setTableName(
"all_ypes");
107 assertEquals(5, resp.schema.columns.size());
108 assertEquals(5, resp.rows.get(0).colVals.size());
109 assertEquals(1, resp.rows.size());
110 assertEquals(
"alltypes", resp.rows.get(0).colVals.get(2).string_val.toLowerCase());
116 TMetadataOpRequest req =
new TMetadataOpRequest();
117 req.opcode = TMetadataOpcode.GET_COLUMNS;
118 req.get_columns_req =
new TGetColumnsReq();
119 req.get_columns_req.setSchemaName(
"functional");
120 req.get_columns_req.setTableName(
"alltypes");
121 req.get_columns_req.setColumnName(
"stri%");
127 assertEquals(23, resp.schema.columns.size());
128 assertEquals(23, resp.rows.get(0).colVals.size());
129 assertEquals(1, resp.rows.size());
130 TResultRow row = resp.rows.get(0);
131 assertEquals(
"functional", row.colVals.get(1).string_val.toLowerCase());
132 assertEquals(
"alltypes", row.colVals.get(2).string_val.toLowerCase());
133 assertEquals(
"string_col", row.colVals.get(3).string_val.toLowerCase());
139 TMetadataOpRequest req =
new TMetadataOpRequest();
140 req.opcode = TMetadataOpcode.GET_CATALOGS;
141 req.get_catalogs_req =
new TGetCatalogsReq();
145 assertEquals(1, resp.schema.columns.size());
146 assertEquals(0, resp.rows.size());
152 TMetadataOpRequest req =
new TMetadataOpRequest();
153 req.opcode = TMetadataOpcode.GET_TABLE_TYPES;
156 assertEquals(1, resp.schema.columns.size());
157 assertEquals(1, resp.rows.get(0).colVals.size());
158 assertEquals(1, resp.rows.size());
159 assertEquals(
"TABLE", resp.rows.get(0).getColVals().
get(0).string_val);
165 TMetadataOpRequest req =
new TMetadataOpRequest();
166 req.opcode = TMetadataOpcode.GET_FUNCTIONS;
167 req.get_functions_req =
new TGetFunctionsReq();
168 req.get_functions_req.setFunctionName(
"sub%");
172 assertEquals(6, resp.schema.columns.size());
173 assertEquals(6, resp.rows.get(0).colVals.size());
175 Set<String> fns = Sets.newHashSet();
176 for (TResultRow row: resp.rows) {
177 String fn = row.colVals.get(2).string_val.toLowerCase();
180 assertEquals(3, fns.size());
182 List<String> expectedResult = Lists.newArrayList();
183 expectedResult.add(
"subdate");
184 expectedResult.add(
"substr");
185 expectedResult.add(
"substring");
186 for (String fn: fns) {
187 assertTrue(fn +
" not found", expectedResult.remove(fn));
193 return fe_.execHiveServer2MetadataOp(req);
TResultSet execMetadataOp(TMetadataOpRequest req)
void TestCatalogNotReady()
static AuthorizationConfig createAuthDisabledConfig()
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)