-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHOENIX-7107 Add support for indexing on SYSTEM.CATALOG table #2048
Open
jpisaac
wants to merge
6
commits into
apache:master
Choose a base branch
from
jpisaac:PHOENIX-7107
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,153
−37
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
78615c3
Initial checkin for SYSTEM indexes
jpisaac 9adc731
Addresses review comments
jpisaac 7154375
Test improvements
jpisaac c475165
Test refactoring and removed SYSTEM schema checks during index creation
jpisaac caf7cbb
Fixed imports
jpisaac 9d9e144
Fixed license
jpisaac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
...lient/src/main/java/org/apache/phoenix/expression/function/DecodeViewIndexIdFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.phoenix.expression.function; | ||
|
||
import org.apache.hadoop.hbase.Cell; | ||
import org.apache.hadoop.hbase.CellUtil; | ||
import org.apache.hadoop.hbase.io.ImmutableBytesWritable; | ||
import org.apache.phoenix.expression.Determinism; | ||
import org.apache.phoenix.expression.Expression; | ||
import org.apache.phoenix.expression.KeyValueColumnExpression; | ||
import org.apache.phoenix.parse.FunctionParseNode; | ||
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction; | ||
import org.apache.phoenix.parse.DecodeViewIndexIdParseNode; | ||
import org.apache.phoenix.parse.PhoenixRowTimestampParseNode; | ||
import org.apache.phoenix.schema.SortOrder; | ||
import org.apache.phoenix.schema.tuple.Tuple; | ||
import org.apache.phoenix.schema.types.PDataType; | ||
import org.apache.phoenix.schema.types.PInteger; | ||
import org.apache.phoenix.schema.types.PLong; | ||
import org.apache.phoenix.schema.types.PSmallint; | ||
|
||
import java.sql.Types; | ||
import java.util.List; | ||
|
||
import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.NULL_DATA_TYPE_VALUE; | ||
import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.VIEW_INDEX_ID_BIGINT_TYPE_PTR_LEN; | ||
|
||
/** | ||
* Function to return the ViewIndexId value based on the ViewIndexIDDataType field. | ||
* Can also be used in sql predicates. | ||
* THe ViewIndexId field value needs to be interpreted based on the type specified in the | ||
* ViewIndexIdDataType field | ||
This is how the various client created view index id's look like: | ||
client VIEW_INDEX_ID(Cell number of bytes) VIEW_INDEX_ID_DATA_TYPE | ||
pre-4.15 2 bytes NULL | ||
post-4.15[config smallint] 2 bytes 5(smallint) | ||
post-4.15[config bigint] 8 bytes -5(bigint) | ||
|
||
VIEW_INDEX_ID_DATA_TYPE, VIEW_INDEX_ID(Cell representation of the data) | ||
NULL, SMALLINT -> RETRIEVE AND CONVERT TO BIGINT | ||
SMALLINT, SMALLINT -> RETRIEVE AND CONVERT TO BIGINT | ||
BIGINT, BIGINT -> DO NOT CONVERT | ||
|
||
*/ | ||
@BuiltInFunction(name = DecodeViewIndexIdFunction.NAME, | ||
nodeClass= DecodeViewIndexIdParseNode.class, | ||
args = {@FunctionParseNode.Argument(allowedTypes = { PLong.class}), | ||
@FunctionParseNode.Argument(allowedTypes = { PInteger.class}) | ||
}) | ||
public class DecodeViewIndexIdFunction extends ScalarFunction { | ||
|
||
public static final String NAME = "DECODE_VIEW_INDEX_ID"; | ||
|
||
public DecodeViewIndexIdFunction() { | ||
} | ||
|
||
/** | ||
* @param children VIEW_INDEX_ID and VIEW_INDEX_ID_DATA_TYPE expressions | ||
*/ | ||
public DecodeViewIndexIdFunction(List<Expression> children) { | ||
super(children); | ||
|
||
// It takes 2 parameters - VIEW_INDEX_ID, VIEW_INDEX_ID_DATA_TYPE. | ||
if ((children.size() != 2) || !children.get(0).getClass().isAssignableFrom( | ||
KeyValueColumnExpression.class) || !children.get(1).getClass().isAssignableFrom( | ||
KeyValueColumnExpression.class)) { | ||
throw new IllegalArgumentException( | ||
"DecodeViewIndexIdFunction should only have a " | ||
+ "VIEW_INDEX_ID and a VIEW_INDEX_ID_DATA_TYPE key value expression." | ||
); | ||
} | ||
if (!(children.get(0).getDataType().equals(PLong.INSTANCE))) { | ||
throw new IllegalArgumentException( | ||
"DecodeViewIndexIdFunction should have an " | ||
+ "VIEW_INDEX_ID key value expression of type PLong" | ||
); | ||
} | ||
|
||
if (!(children.get(1).getDataType().equals(PInteger.INSTANCE))) { | ||
throw new IllegalArgumentException( | ||
"DecodeViewIndexIdFunction should have an " | ||
+ "VIEW_INDEX_ID_DATA_TYPE key value expression of type PLong" | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { | ||
if (tuple == null) { | ||
return false; | ||
} | ||
|
||
byte[] viewIndexIdCF = ((KeyValueColumnExpression) children.get(0)).getColumnFamily(); | ||
byte[] viewIndexIdCQ = ((KeyValueColumnExpression) children.get(0)).getColumnQualifier(); | ||
byte[] viewIndexIdTypeCF = ((KeyValueColumnExpression) children.get(1)).getColumnFamily(); | ||
byte[] viewIndexIdTypeCQ = ((KeyValueColumnExpression) children.get(1)).getColumnQualifier(); | ||
|
||
Cell viewIndexIdCell = tuple.getValue(viewIndexIdCF, viewIndexIdCQ); | ||
Cell viewIndexIdDataTypeCell = tuple.getValue(viewIndexIdTypeCF, viewIndexIdTypeCQ); | ||
|
||
|
||
/* | ||
This is combination of diff client created view index looks like: | ||
client VIEW_INDEX_ID(Cell number of bytes) VIEW_INDEX_ID_DATA_TYPE | ||
pre-4.15 2 bytes NULL | ||
post-4.15[config smallint] 2 bytes 5(smallint) | ||
post-4.15[config bigint] 8 bytes -5(bigint) | ||
|
||
VIEW_INDEX_ID_DATA_TYPE, VIEW_INDEX_ID(Cell representation of the data) | ||
NULL, SMALLINT -> RETRIEVE AND CONVERT TO BIGINT | ||
SMALLINT, SMALLINT -> RETRIEVE AND CONVERT TO BIGINT | ||
BIGINT, BIGINT -> DO NOT CONVERT | ||
|
||
*/ | ||
|
||
if (viewIndexIdCell != null) { | ||
int type = NULL_DATA_TYPE_VALUE; | ||
if (viewIndexIdDataTypeCell != null) { | ||
type = (Integer) PInteger.INSTANCE.toObject( | ||
viewIndexIdDataTypeCell.getValueArray(), | ||
viewIndexIdDataTypeCell.getValueOffset(), | ||
viewIndexIdDataTypeCell.getValueLength(), | ||
PInteger.INSTANCE, | ||
SortOrder.ASC); | ||
} | ||
|
||
ImmutableBytesWritable columnValue = | ||
new ImmutableBytesWritable(CellUtil.cloneValue(viewIndexIdCell)); | ||
if ((type == NULL_DATA_TYPE_VALUE || type == Types.SMALLINT) && (viewIndexIdCell.getValueLength() < | ||
VIEW_INDEX_ID_BIGINT_TYPE_PTR_LEN)) { | ||
byte[] newBytes = PLong.INSTANCE.toBytes(PSmallint.INSTANCE.toObject(columnValue.get())); | ||
ptr.set(newBytes, 0, newBytes.length); | ||
} else { | ||
ptr.set(columnValue.get(), columnValue.getOffset(), columnValue.getLength()); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public PDataType getDataType() { | ||
return PLong.INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean isStateless() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Determinism getDeterminism() { | ||
return Determinism.PER_ROW; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
phoenix-core-client/src/main/java/org/apache/phoenix/parse/DecodeViewIndexIdParseNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.phoenix.parse; | ||
|
||
import org.apache.phoenix.compile.StatementContext; | ||
import org.apache.phoenix.expression.Expression; | ||
import org.apache.phoenix.expression.function.DecodeViewIndexIdFunction; | ||
import org.apache.phoenix.expression.function.FunctionExpression; | ||
import org.apache.phoenix.query.QueryConstants; | ||
import org.apache.phoenix.util.IndexUtil; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; | ||
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; | ||
|
||
public class DecodeViewIndexIdParseNode extends FunctionParseNode { | ||
|
||
DecodeViewIndexIdParseNode(String name, List<ParseNode> children, | ||
BuiltInFunctionInfo info) { | ||
super(name, children, info); | ||
// It takes 2 parameters - VIEW_INDEX_ID, VIEW_INDEX_ID_DATA_TYPE. | ||
if (children.size() != 2) { | ||
throw new IllegalArgumentException( | ||
"DecodeViewIndexIdParseNode should only have " | ||
+ "VIEW_INDEX_ID and VIEW_INDEX_ID_DATA_TYPE parse nodes." | ||
); | ||
} | ||
if (children.get(0).getClass().isAssignableFrom(ColumnParseNode.class) | ||
&& children.get(1).getClass().isAssignableFrom(ColumnParseNode.class) | ||
&& (!(((ColumnParseNode) children.get(0)).getName().equals(VIEW_INDEX_ID)) | ||
|| !(((ColumnParseNode) children.get(1)).getName().equals(VIEW_INDEX_ID_DATA_TYPE))) | ||
) { | ||
throw new IllegalArgumentException( | ||
"DecodeViewIndexIdParseNode should only have " | ||
+ "VIEW_INDEX_ID and VIEW_INDEX_ID_DATA_TYPE parse nodes." | ||
); | ||
} | ||
|
||
// CastPastNode is generated during IndexStatement rewriting | ||
if (children.get(0).getClass().isAssignableFrom(CastParseNode.class) | ||
&& children.get(1).getClass().isAssignableFrom(CastParseNode.class) | ||
&& (!((ColumnParseNode) (((CastParseNode) children.get(0)).getChildren().get(0))).getName().equals( | ||
IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, VIEW_INDEX_ID)) | ||
|| !((ColumnParseNode) (((CastParseNode) children.get(1)).getChildren().get(0))).getName().equals( | ||
IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, VIEW_INDEX_ID_DATA_TYPE))) | ||
) { | ||
throw new IllegalArgumentException( | ||
"DecodeViewIndexIdParseNode should only have " | ||
+ "VIEW_INDEX_ID and VIEW_INDEX_ID_DATA_TYPE parse nodes." | ||
); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public FunctionExpression create(List<Expression> children, StatementContext context) | ||
throws SQLException { | ||
return new DecodeViewIndexIdFunction(children); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments here are for the PHOENIX_ROW_TIMESTAMP() function. Let's update them.