[
https://issues.apache.org/jira/browse/PHOENIX-6847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17648739#comment-17648739
]
Geoffrey Jacoby commented on PHOENIX-6847:
------------------------------------------
Some years ago I asked James Taylor, who led the original development of
Phoenix, about a similar issue, and he said something like "The only public API
in Phoenix is JDBC". In this case, the above way using DatabaseMetaData is the
correct way to do it in JDBC.
That said, I've often treated PhoenixRuntime.getTable() and the PTable data
structure as quasi-public APIs, because they're both easier to work with and
much more performant than using JDBC.
This is because the Phoenix client can cache PTables, but every call to JDBC's
metadata APIs hits SYSTEM.CATALOG. And there are some subtleties in how you
structure the JDBC call -- whether you use null or "" in the catalog field if
you're looking for a non-tenant object -- that have a huge perf impact on query
perf if you have a large SYSTEM.CATALOG.
This also can create hard-to-spot correctness bugs. For example, in the code
above, the customer is _probably_ wrong to pass in null for the catalog. They
probably either are interested in a view for a particular tenant, in which case
they should pass in the tenant ID for the catalog, or they know it's a globally
owned view, in which case they should pass in the empty string (which I believe
enforces "TENANT_ID IS NULL"). Otherwise they could get a false positive if
some other tenant has a view by the same name.
So in this case, I don't have a problem with wrapping it in a PhoenixRuntime
API, though I wouldn't want _all_ of PhoenixRuntime to be considered public.
Another option would be to do it as a SQL command -- we already have a SHOW
TABLES command in PHOENIX-5543, so there could be a specific SHOW VIEWS.
> Provide a crisp API to check if a view exists.
> ----------------------------------------------
>
> Key: PHOENIX-6847
> URL: https://issues.apache.org/jira/browse/PHOENIX-6847
> Project: Phoenix
> Issue Type: Bug
> Reporter: Rushabh Shah
> Priority: Major
>
> Currently customer using phoenix runs the following statements to check if a
> view exists or not.
> {noformat}
> public static boolean checkTableViewExists(Connection connection, String
> schema, String viewName)
> throws SQLException {
> DatabaseMetaData meta = connection.getMetaData();
> ResultSet resultSet = meta.getTables(null, schema, viewName, new String[]
> {"VIEW"});
> return resultSet.next();
> }
> {noformat}
> IMHO this is NOT very user friendly.
> We need to provide either of the 2 APIs
> {noformat}
> public PTable getView(String viewName, String tenantID); OR
> public boolean viewExists(String viewName, String tenantID);
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)