Reputation: 71
My goal is to create a parameterized view in Impala so users can easily change values in a query. If I run below query, for example, in HUE, is possible to introduce a value.
SELECT * FROM customers WHERE customer_id = ${id}
But I would like to create a view as follows, that when you run it, it asks you for the value you want to search. But this way is not working:
CREATE VIEW test AS SELECT * FROM customers WHERE customer_id = ${id}
Someone know if it is possible?
Many thanks
Upvotes: 3
Views: 1979
Reputation: 517
When you creating a view, it takes the actual variable's value.
Two workarounds exist:
CREATE VIEW test AS SELECT * FROM customers JOIN id_table ON customer_id = id_tableid
Two above mentioned workarounds work but not ideal. My suggestion is to use Hive for parametrized view creation. You can create a GenericUDF via which you can access hive configuration and read the variable and perform filtration. You can't use it for Impala.
SELECT Generic_UDF(array(customer_id)) FROM customers
GenericUDFs has method configure you can use it to read the hive variable:
public void configure(MapredContext mapredContext) {
String name = mapredContext.getJobConf().get("name");
}
Upvotes: 1
Reputation: 7082
You could do the opposite, e.g. parameterize the query on the view instead
Upvotes: 0