This is an automated email from the ASF dual-hosted git repository.
jaanai pushed a commit to branch 4.x-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x-HBase-1.2 by this push:
new 59df3d8 PHOENIX-5226 The format of VIEW_MODIFIED_PROPERTY_BYTES is
incorrect as a tag of the cell
59df3d8 is described below
commit 59df3d82154db2f4f663b3790e7c0214f57a2c3e
Author: jaanai <[email protected]>
AuthorDate: Thu Apr 18 11:51:53 2019 +0800
PHOENIX-5226 The format of VIEW_MODIFIED_PROPERTY_BYTES is incorrect as a
tag of the cell
---
.../phoenix/coprocessor/MetaDataEndpointImpl.java | 4 +-
.../org/apache/phoenix/query/QueryConstants.java | 4 +-
.../org/apache/phoenix/util/MetaDataUtilTest.java | 49 ++++++++++++++++++++++
3 files changed, 55 insertions(+), 2 deletions(-)
diff --git
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index fa374a7..37f0c5e 100644
---
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -76,6 +76,7 @@ import static
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT_BYT
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE_BYTES;
import static
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE_BYTES;
import static
org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_COUNT;
+import static
org.apache.phoenix.query.QueryConstants.VIEW_MODIFIED_PROPERTY_TAG_TYPE;
import static org.apache.phoenix.schema.PTableType.INDEX;
import static org.apache.phoenix.schema.PTableType.TABLE;
import static org.apache.phoenix.schema.PTableImpl.getColumnsToClone;
@@ -113,6 +114,7 @@ import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Mutation;
@@ -466,7 +468,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol
implements Coprocesso
private static final int LINK_TYPE_INDEX = 0;
// Used to add a tag to a cell when a view modifies a table property to
indicate that this
// property should not be derived from the base table
- private static final byte[] VIEW_MODIFIED_PROPERTY_BYTES =
Bytes.toBytes(1);
+ public static final byte[] VIEW_MODIFIED_PROPERTY_BYTES =
Tag.fromList(ImmutableList.<Tag>of(new Tag(VIEW_MODIFIED_PROPERTY_TAG_TYPE,
Bytes.toBytes(1))));
private static final KeyValue CLASS_NAME_KV =
createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES,
CLASS_NAME_BYTES);
private static final KeyValue JAR_PATH_KV =
createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, JAR_PATH_BYTES);
diff --git
a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
index 6f9e8c1..2e95483 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
@@ -161,7 +161,9 @@ public interface QueryConstants {
public static final int NANOS_IN_SECOND = BigDecimal.valueOf(Math.pow(10,
9)).intValue();
public static final int DIVERGED_VIEW_BASE_COLUMN_COUNT = -100;
public static final int BASE_TABLE_BASE_COLUMN_COUNT = -1;
-
+
+ // custom TagType
+ public static final byte VIEW_MODIFIED_PROPERTY_TAG_TYPE = (byte) 70;
/**
* We mark counter values 0 to 10 as reserved. Value 0 is used by {@link
#ENCODED_EMPTY_COLUMN_NAME}. Values 1-10
* are reserved for special column qualifiers returned by Phoenix
co-processors.
diff --git
a/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
index 59c7739..5c70ef8 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
@@ -17,6 +17,8 @@
*/
package org.apache.phoenix.util;
+import static
org.apache.phoenix.coprocessor.MetaDataEndpointImpl.VIEW_MODIFIED_PROPERTY_BYTES;
+import static
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY_BYTES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -28,6 +30,7 @@ import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.VersionInfo;
import org.apache.phoenix.coprocessor.MetaDataProtocol;
@@ -37,9 +40,13 @@ import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
import org.apache.phoenix.hbase.index.util.VersionUtil;
import org.apache.phoenix.query.HBaseFactoryProvider;
import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
import org.junit.Test;
import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import static org.apache.hadoop.hbase.HConstants.EMPTY_BYTE_ARRAY;
import static
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
@@ -228,5 +235,47 @@ public class MetaDataUtilTest {
return put;
}
+ @Test
+ public void testConditionallyAddTagsToPutCells( ) {
+ List<Tag> tags = Tag.asList(VIEW_MODIFIED_PROPERTY_BYTES, 0,
VIEW_MODIFIED_PROPERTY_BYTES.length);
+ assertEquals(tags.size(), 1);
+ Tag expectedTag = tags.get(0);
+
+ String version = VersionInfo.getVersion();
+ KeyValueBuilder builder = KeyValueBuilder.get(version);
+ KeyValue kv = builder.buildPut(wrap(ROW), wrap(TABLE_FAMILY_BYTES),
wrap(UPDATE_CACHE_FREQUENCY_BYTES), wrap(
+ PLong.INSTANCE.toBytes(0)));
+ Put put = new Put(ROW);
+ KeyValueBuilder.addQuietly(put, null, kv);
+
+ MetaDataUtil.conditionallyAddTagsToPutCells(put, TABLE_FAMILY_BYTES,
UPDATE_CACHE_FREQUENCY_BYTES, PInteger.INSTANCE.toBytes(1),
VIEW_MODIFIED_PROPERTY_BYTES);
+
+ Cell cell = put.getFamilyCellMap().get(TABLE_FAMILY_BYTES).get(0);
+
+ // To check the cell tag whether view has modified this property
+ assertTrue(Bytes.compareTo(expectedTag.getBuffer(),
concatTags(EMPTY_BYTE_ARRAY, cell)) == 0);
+ assertTrue(Bytes.contains(concatTags(EMPTY_BYTE_ARRAY, cell),
expectedTag.getBuffer()));
+
+ // To check tag data can be correctly deserialized
+ byte[] tagsBytes = CellUtil.getTagArray(cell);
+ Iterator<Tag> tagIterator = CellUtil.tagsIterator(tagsBytes, 0,
tagsBytes.length);
+ assertTrue(tagIterator.hasNext());
+ Tag actualTag = tagIterator.next();
+ assertTrue(Bytes.compareTo(actualTag.getBuffer(),
actualTag.getTagOffset(), actualTag.getTagLength(),
+ expectedTag.getBuffer(), expectedTag.getTagOffset(),
expectedTag.getTagLength()) == 0);
+ assertFalse(tagIterator.hasNext());
+ }
+
+ private static byte[] concatTags(byte[] tags, Cell cell) {
+ int cellTagsLen = cell.getTagsLength();
+ if (cellTagsLen == 0) {
+ return tags;
+ }
+ byte[] b = new byte[tags.length + cellTagsLen];
+ int pos = Bytes.putBytes(b, 0, tags, 0, tags.length);
+ Bytes.putBytes(b, pos, cell.getTagsArray(), cell.getTagsOffset(),
cellTagsLen);
+ return b;
+ }
+
}