-
Notifications
You must be signed in to change notification settings - Fork 227
Tweak syntax for multi-tenant tables #592
Comments
I like the explicit MULTI_TENANT='true' on the base table. We should consider surfacing that in DatabaseMetaData in some form. |
Agreed. Just need to return that column (at the end of the select) in the On Thu, Dec 19, 2013 at 12:30 PM, Eli Levine [email protected]:
|
Just curious to know that why we have not considered to call this create table as "CREATE TENANT TABLE" or DERIVED TABLE for example: CREATE [TENANT | DERIVED ] TABLE my_schema.my_table (column1 VARCHAR) LIKE my_base_schema.base_table AS 'abc'; Since CREATE TABLE and LIKE give me the impression that we are creating another table in HBase having |
Good points, @AakashPradeep. Perhaps using LIKE would be confusing. I'm considering the following syntax:
|
I've made the above changes, but the more I think about it, the more I think these concepts fit into the SQL concept of a VIEW. The multi-tenant aspects put a bit of a wrinkle in things, but we can infer a VIEW is multi-tenant based on the connection being a tenant-specific connection. Here's an example:
Note that we could potentially still require the MULT_TENANT=true property above to be more explicit about allowing the creation of tenant-specific tables from a given table. To create a multi-tenant table, you could connect through a tenant-specific connection and do the following:
Since you've connected through a tenant-specific connection, the WHERE tenant_id=? clause would automatically be tacked on. You could optionally add additional columns during the CREATE like this:
To create a multi-tenant, multi-type table, you could add a WHERE clause like this:
You could also create a VIEW from a non tenant-specific connection. You could use any WHERE clause, but for your VIEW to be updateable, you could only use equality expressions. These expressions would then be applied automatically for UPSERT statements. Initially, we might only support SELECT *, but we could support a list of columns pretty easily and eventually when we have derived tables, even expressions. |
This is really cool. If I read this right, you are proposing:
I like CREATE VIEW more than DERIVE. The term "view" represents well the fact that these multi-tenant and/or multi-type tables are a sliver of data in a physical HBase table. I also like the explicit MULTI_TENANT=true property on base tables. We might want to consider @AakashPradeep's suggestion of adding the keyword TENANT in there to make things more explicit and allow Phoenix to fail if a tenant-specific table was created over a non-tenant-specific connection and visa versa:
The flexibility of the WHERE clause in defining how multi-type is great. One thing of concern is that currently |
Having I'll start down this path and let folks know if I hit any roadblocks. |
I will write this up on the wiki too, but the above is now implemented:
Phoenix figures out if the view is "updatable" based on the WHERE clause in the CREATE VIEW statement. The basic rule is that it's updatable if you only have equality expressions with a column reference and a literal separated by ANDs, like this:
In these cases, Phoenix can infer the value that the columns have, so it can allow you to update through the view. For example, you could do this:
You get an error, though, if you try to update through a view and change anything that would make the WHERE clause not be satisfied. For example, this would throw an exception, since you're trying to set a to something other than 'foo':
If your view isn't updatable, you get an error if you try to do an UPSERT or DELETE on it. For example, the following would not be updatable:
It's still valid, though, and you can query through it and even derive other views from it, but you just can't use it in an UPSERT or DELETE statement. Most RDBMS have the concept of an updatable view. The restrictions on what is and what isn't updatable is not standardized, though. I thought we'd start simple on this - we could potentially make more views updatable down the road. |
The current syntax relies on a BASE_TABLE property, which is somewhat outside of the SQL syntax. Here's an example of the current syntax:
Here's an example of the proposed new syntax:
This would also be allowed
as would this, but only if the table has no tenant-specific tables:
Changes include:
The text was updated successfully, but these errors were encountered: