[
https://issues.apache.org/jira/browse/PHOENIX-2795?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15260986#comment-15260986
]
James Taylor commented on PHOENIX-2795:
---------------------------------------
Thanks for the fixes, [~tdsilva]. One question on a corner case: if the where
clause looked like this for a view:
{{WHERE a = 'x OR a = 'y'}} would your logic do to add the AND do the right
thing as I'm thinking it might end up as {{WHERE a ='x' OR a = 'y' AND b =
12345}}. You might need to grab the string based on the known string length of
"SELECT * FROM schema.table WHERE ", which is ugly but perhaps necessary (and
can be hidden in another QueryUtil function at least).
One other very recommendation here:
{code}
+ MetaDataUtil.getMutationValue(tableHeaderPut,
VIEW_STATEMENT_BYTES, kvBuilder, ptr);
+ byte[] value = ptr.copyBytesIfNecessary();
+ byte[] viewStatement = null;
+ // if we have an existing where clause add the auto
partition where clause to it
+ if (!Bytes.equals(value,
QueryConstants.EMPTY_COLUMN_VALUE_BYTES))
+ viewStatement = Bytes.add(value, Bytes.toBytes(" AND
"), Bytes.toBytes(autoPartitionWhere));
+ else
+ viewStatement =
Bytes.toBytes(QueryUtil.getViewStatement(parentTable.getSchemaName().getString(),
parentTable.getTableName().getString(), autoPartitionWhere));
{code}
How about something like this instead?
{code}
+ MetaDataUtil.getMutationValue(tableHeaderPut,
VIEW_STATEMENT_BYTES, kvBuilder, ptr);
+ byte[] viewStatement = null;
+ // if we have an existing where clause add the auto
partition where clause to it
+ if (MetaDataUtil.getMutationValue(tableHeaderPut,
VIEW_STATEMENT_BYTES, kvBuilder, ptr)) {
+ viewStatement = Bytes.add(ptr.copyBytesIfNecessary(),
Bytes.toBytes(" AND "), Bytes.toBytes(autoPartitionWhere));
+ } else {
+ viewStatement =
Bytes.toBytes(QueryUtil.getViewStatement(parentTable.getSchemaName().getString(),
parentTable.getTableName().getString(), autoPartitionWhere));
+ }
{code}
> Support auto partition for views
> --------------------------------
>
> Key: PHOENIX-2795
> URL: https://issues.apache.org/jira/browse/PHOENIX-2795
> Project: Phoenix
> Issue Type: Sub-task
> Reporter: James Taylor
> Assignee: Thomas D'Silva
> Labels: argus
> Fix For: 4.8.0
>
> Attachments: PHOENIX-2795-v2.patch, PHOENIX-2795.patch
>
>
> When a view or base table is created, we should have an string
> AUTO_PARTITION_SEQ parameter on CREATE TABLE which uses a sequence based on
> the argument on the server side to generate a WHERE clause with the first PK
> column and the unique identifier from the sequence.
> For example:
> {code}
> CREATE SEQUENCE metric_id_seq;
> CREATE TABLE metric_table (metric_id INTEGER, val DOUBLE)
> AUTO_PARTITION_SEQ=metric_id_seq;
> CREATE VIEW my_view1 AS SELECT * FROM base_table;
> {code}
> would tack on a WHERE clause base on the next value in a sequence, logically
> like this:
> {code}
> WHERE partition_id = NEXT VALUE FROM metric_id_seq
> {code}
> It's important that the sequence be generated *after* the check for the
> existence of the view so that we don't burn sequence values needlessly if the
> view already exists.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)