15 package com.cloudera.impala.analysis;
19 import junit.framework.Assert;
31 import com.cloudera.impala.thrift.TAccessEvent;
32 import com.cloudera.impala.thrift.TCatalogObjectType;
33 import com.google.common.collect.Sets;
43 Set<TAccessEvent> accessEvents =
45 Assert.assertEquals(accessEvents, Sets.newHashSet(
46 new TAccessEvent(
"functional.alltypesagg", TCatalogObjectType.TABLE,
"SELECT")));
51 Assert.assertEquals(accessEvents, Sets.newHashSet(
52 new TAccessEvent(
"functional.view_view", TCatalogObjectType.VIEW,
"SELECT"),
53 new TAccessEvent(
"functional.alltypes_view", TCatalogObjectType.VIEW,
"SELECT"),
54 new TAccessEvent(
"functional.alltypes", TCatalogObjectType.TABLE,
"SELECT")
59 "select a.* from (select * from functional.alltypesagg) a");
60 Assert.assertEquals(accessEvents, Sets.newHashSet(
61 new TAccessEvent(
"functional.alltypesagg", TCatalogObjectType.TABLE,
"SELECT")));
65 "select item from functional.allcomplextypes.int_array_col");
66 Assert.assertEquals(accessEvents, Sets.newHashSet(
67 new TAccessEvent(
"functional.allcomplextypes",
68 TCatalogObjectType.TABLE,
"SELECT")));
70 "select item from functional.allcomplextypes a, a.int_array_col");
71 Assert.assertEquals(accessEvents, Sets.newHashSet(
72 new TAccessEvent(
"functional.allcomplextypes",
73 TCatalogObjectType.TABLE,
"SELECT")));
79 "select * from functional.alltypes union all " +
80 "select * from functional_rc.alltypes");
81 Assert.assertEquals(accessEvents, Sets.newHashSet(
82 new TAccessEvent(
"functional.alltypes", TCatalogObjectType.TABLE,
"SELECT"),
83 new TAccessEvent(
"functional_rc.alltypes", TCatalogObjectType.TABLE,
"SELECT")));
89 "insert into functional.alltypes " +
90 "partition(month,year) select * from functional_rc.alltypes");
91 Assert.assertEquals(accessEvents, Sets.newHashSet(
92 new TAccessEvent(
"functional_rc.alltypes", TCatalogObjectType.TABLE,
"SELECT"),
93 new TAccessEvent(
"functional.alltypes", TCatalogObjectType.TABLE,
"INSERT")));
97 "insert into functional.alltypes partition(month,year) " +
98 "select b.* from functional.alltypesagg a join (select * from " +
99 "functional_rc.alltypes) b on (a.int_col = b.int_col)");
100 Assert.assertEquals(accessEvents, Sets.newHashSet(
101 new TAccessEvent(
"functional.alltypesagg", TCatalogObjectType.TABLE,
"SELECT"),
102 new TAccessEvent(
"functional_rc.alltypes", TCatalogObjectType.TABLE,
"SELECT"),
103 new TAccessEvent(
"functional.alltypes", TCatalogObjectType.TABLE,
"INSERT")));
110 "with t as (select * from functional.alltypesagg) select * from t");
111 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
112 "functional.alltypesagg", TCatalogObjectType.TABLE,
"SELECT")));
116 "with t as (select * from functional.alltypes_view) select * from t");
117 Assert.assertEquals(accessEvents, Sets.newHashSet(
119 "functional.alltypes_view", TCatalogObjectType.VIEW,
"SELECT"),
120 new TAccessEvent(
"functional.alltypes", TCatalogObjectType.TABLE,
"SELECT")));
124 Assert.assertEquals(0, accessEvents.size());
128 "with t as (select * from functional.alltypes) select 'abc'");
129 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
130 "functional.alltypes", TCatalogObjectType.TABLE,
"SELECT")));
132 "select * from functional_seq.alltypes");
133 Assert.assertEquals(accessEvents, Sets.newHashSet(
134 new TAccessEvent(
"functional.alltypes", TCatalogObjectType.TABLE,
"SELECT"),
136 "functional_seq.alltypes", TCatalogObjectType.TABLE,
"SELECT")));
141 Set<TAccessEvent> accessEvents =
143 Assert.assertEquals(accessEvents, Sets.newHashSet(
144 new TAccessEvent(
"functional.alltypesagg", TCatalogObjectType.TABLE,
"SELECT")));
150 Assert.assertEquals(accessEvents, Sets.newHashSet(
151 new TAccessEvent(
"functional", TCatalogObjectType.DATABASE,
"ANY")));
157 Set<TAccessEvent> accessEvents =
160 Assert.assertEquals(0, accessEvents.size());
162 Assert.assertEquals(0, accessEvents.size());
167 Set<TAccessEvent> accessEvents =
169 Assert.assertEquals(accessEvents, Sets.newHashSet(
170 new TAccessEvent(
"tpch.new_table", TCatalogObjectType.TABLE,
"CREATE")));
175 Assert.assertEquals(accessEvents, Sets.newHashSet(
176 new TAccessEvent(
"tpch.lineitem", TCatalogObjectType.TABLE,
"VIEW_METADATA"),
177 new TAccessEvent(
"tpch.new_lineitem", TCatalogObjectType.TABLE,
"CREATE")));
180 +
"'/test-warehouse/schemas/zipcode_incomes.parquet'");
181 Assert.assertEquals(accessEvents, Sets.newHashSet(
182 new TAccessEvent(
"tpch.new_table", TCatalogObjectType.TABLE,
"CREATE")));
188 "create view tpch.new_view as select * from functional.alltypesagg");
189 Assert.assertEquals(accessEvents, Sets.newHashSet(
190 new TAccessEvent(
"functional.alltypesagg", TCatalogObjectType.TABLE,
"SELECT"),
191 new TAccessEvent(
"tpch.new_view", TCatalogObjectType.VIEW,
"CREATE")));
197 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
198 "newdb", TCatalogObjectType.DATABASE,
"CREATE")));
204 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
205 "tpch", TCatalogObjectType.DATABASE,
"DROP")));
211 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
212 "tpch.lineitem", TCatalogObjectType.TABLE,
"DROP")));
217 Set<TAccessEvent> accessEvents =
219 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
220 "functional_seq_snap.alltypes_view", TCatalogObjectType.VIEW,
"DROP")));
227 "ALTER TABLE functional_seq_snap.alltypes ADD COLUMNS (c1 int)");
228 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
229 "functional_seq_snap.alltypes", TCatalogObjectType.TABLE,
"ALTER")));
232 "ALTER TABLE functional_seq_snap.alltypes RENAME TO functional_seq_snap.t1");
233 Assert.assertEquals(accessEvents, Sets.newHashSet(
235 "functional_seq_snap.alltypes", TCatalogObjectType.TABLE,
"ALTER"),
236 new TAccessEvent(
"functional_seq_snap.t1", TCatalogObjectType.TABLE,
"CREATE")));
242 "ALTER VIEW functional_seq_snap.alltypes_view " +
243 "rename to functional_seq_snap.v1");
244 Assert.assertEquals(accessEvents, Sets.newHashSet(
246 "functional_seq_snap.alltypes_view", TCatalogObjectType.VIEW,
"ALTER"),
247 new TAccessEvent(
"functional_seq_snap.v1", TCatalogObjectType.VIEW,
"CREATE")));
253 "COMPUTE STATS functional_seq_snap.alltypes");
254 Assert.assertEquals(accessEvents, Sets.newHashSet(
256 "functional_seq_snap.alltypes", TCatalogObjectType.TABLE,
"ALTER")));
262 "DROP STATS functional_seq_snap.alltypes");
263 Assert.assertEquals(accessEvents, Sets.newHashSet(
265 "functional_seq_snap.alltypes", TCatalogObjectType.TABLE,
"ALTER")));
270 Set<TAccessEvent> accessEvents =
272 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
273 "functional.alltypesagg", TCatalogObjectType.TABLE,
"VIEW_METADATA")));
276 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
277 "functional.complex_view", TCatalogObjectType.VIEW,
"VIEW_METADATA")));
282 String[] statsQuals =
new String[]{
"partitions",
"table stats",
"column stats" };
283 for (String qual: statsQuals) {
284 Set<TAccessEvent> accessEvents =
286 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
287 "functional.alltypes", TCatalogObjectType.TABLE,
"VIEW_METADATA")));
293 Set<TAccessEvent> accessEvents =
295 Assert.assertEquals(accessEvents, Sets.newHashSet(
new TAccessEvent(
296 "functional.alltypesagg", TCatalogObjectType.TABLE,
"VIEW_METADATA")));
302 "'hdfs://localhost:20500/test-warehouse/tpch.lineitem' " +
303 "into table functional.alltypes partition(month=10, year=2009)");
304 Assert.assertEquals(accessEvents, Sets.newHashSet(
305 new TAccessEvent(
"functional.alltypes", TCatalogObjectType.TABLE,
"INSERT")));
314 "server1",
"/does/not/exist",
"");
322 node.analyze(analyzer);
323 analyzer.authorize(fe.getAuthzChecker());
324 Assert.fail(
"Expected AuthorizationException");
325 }
catch (AuthorizationException e) {
326 Assert.assertEquals(1, analyzer.getAccessEvents().size());
334 " functional.alltypesagg a join functional.alltypesagg b on a.id = b.id");
335 Assert.assertEquals(accessEvents, Sets.newHashSet(
336 new TAccessEvent(
"_impala_builtins", TCatalogObjectType.DATABASE,
"VIEW_METADATA"),
337 new TAccessEvent(
"functional.alltypesagg", TCatalogObjectType.TABLE,
"SELECT")));
348 return analyzer.getAccessEvents();
void TestShowCreateTable()
static TQueryCtx createQueryContext()
Analyzer createAnalyzer(String defaultDb)
ParseNode AnalyzesOk(String stmt)
void TestCreateDatabase()
ParseNode ParsesOk(String stmt)
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
Set< TAccessEvent > AnalyzeAccessEvents(String stmt)
void TestAccessEventsOnAuthFailure()
static final String DEFAULT_DB
void TestResetMetadataEvents()