[ 
https://issues.apache.org/jira/browse/PHOENIX-476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15507199#comment-15507199
 ] 

James Taylor commented on PHOENIX-476:
--------------------------------------

Thanks for the patch, [~kliew]. Nice work so far - it's coming along nicely. 
Here's some comments:
- Instead of using ExpressionUtil.isConstant(), use the following check:
{code}
expression.isStateless() && expression.getDeterminism() == Determinism.ALWAYS
{code}
Maybe we should rename ExpressionUtil.isConstant() to 
ExpressionUtil.isConstantPerStatement() and use the above for a new 
ExpressionUtil.isConstant()?
- We can't keep trailing nulls - that'll cause a world of problems. But on the 
plus side, since we put default values explicitly into rows, we don't need to 
wrap RowKeyExpression with getDefaultExpression. So you can just change this in 
ExpressionCompiler:
{code}
+        if (column.getDefaultExpression() != null && 
!SchemaUtil.isPKColumn(column)) {
+            expression = new DefaultValueExpression(Arrays.asList(expression, 
column.getDefaultExpression()));
+        }
{code}
- Minor nit. Instead of ptr.copyBytes(), use 
ByteUtil.copyKeyBytesIfNecessary(ptr) as that prevents a copy when it's not 
necessary.
- Not sure on the test failure, but I suspect you'll want to tweak the 
PRowImpl.setValue() call in PTableImpl. You'll want to be careful about the 
{{isNull}} setting and the case when there's a default value. You likely need 
to differentiate here between byteValue of null and a byteValue of an empty 
byteValue:
{code}
        public void setValue(PColumn column, byte[] byteValue) {
            deleteRow = null;
            byte[] family = column.getFamilyName().getBytes();
            byte[] qualifier = column.getName().getBytes();
            PDataType<?> type = column.getDataType();
            // Check null, since some types have no byte representation for null
            boolean isNull = type.isNull(byteValue);  // TODO: this might need 
to change
{code}

> Support declaration of DEFAULT in CREATE statement
> --------------------------------------------------
>
>                 Key: PHOENIX-476
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-476
>             Project: Phoenix
>          Issue Type: Task
>    Affects Versions: 3.0-Release
>            Reporter: James Taylor
>            Assignee: Kevin Liew
>              Labels: enhancement
>         Attachments: PHOENIX-476.2.patch, PHOENIX-476.3.patch, 
> PHOENIX-476.patch
>
>
> Support the declaration of a default value in the CREATE TABLE/VIEW statement 
> like this:
>     CREATE TABLE Persons (
>         Pid int NOT NULL PRIMARY KEY,
>         LastName varchar(255) NOT NULL,
>         FirstName varchar(255),
>         Address varchar(255),
>         City varchar(255) DEFAULT 'Sandnes'
>     )
> To implement this, we'd need to:
> 1. add a new DEFAULT_VALUE key value column in SYSTEM.TABLE and pass through 
> the value when the table is created (in MetaDataClient).
> 2. always set NULLABLE to ResultSetMetaData.columnNoNulls if a default value 
> is present, since the column will never be null.
> 3. add a getDefaultValue() accessor in PColumn
> 4.  for a row key column, during UPSERT use the default value if no value was 
> specified for that column. This could be done in the PTableImpl.newKey method.
> 5.  for a key value column with a default value, we can get away without 
> incurring any storage cost. Although a little bit of extra effort than if we 
> persisted the default value on an UPSERT for key value columns, this approach 
> has the benefit of not incurring any storage cost for a default value.
>     * serialize any default value into KeyValueColumnExpression
>     * in the evaluate method of KeyValueColumnExpression, conditionally use 
> the default value if the column value is not present. If doing partial 
> evaluation, you should not yet return the default value, as we may not have 
> encountered the the KeyValue for the column yet (since a filter evaluates 
> each time it sees each KeyValue, and there may be more than one KeyValue 
> referenced in the expression). Partial evaluation is determined by calling 
> Tuple.isImmutable(), where false means it is NOT doing partial evaluation, 
> while true means it is.
>     * modify EvaluateOnCompletionVisitor by adding a visitor method for 
> RowKeyColumnExpression and KeyValueColumnExpression to set 
> evaluateOnCompletion to true if they have a default value specified. This 
> will cause filter evaluation to execute one final time after all KeyValues 
> for a row have been seen, since it's at this time we know we should use the 
> default value.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to