[ https://issues.apache.org/jira/browse/PHOENIX-628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14515180#comment-14515180 ]
ASF GitHub Bot commented on PHOENIX-628: ---------------------------------------- Github user JamesRTaylor commented on a diff in the pull request: https://github.com/apache/phoenix/pull/76#discussion_r29200389 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java --- @@ -30,134 +31,145 @@ public class PVarchar extends PDataType<String> { - public static final PVarchar INSTANCE = new PVarchar(); - - private PVarchar() { - super("VARCHAR", Types.VARCHAR, String.class, null, 0); - } - - @Override - public byte[] toBytes(Object object) { - // TODO: consider using avro UTF8 object instead of String - // so that we get get the size easily - if (object == null) { - return ByteUtil.EMPTY_BYTE_ARRAY; - } - return Bytes.toBytes((String) object); - } - - @Override - public int toBytes(Object object, byte[] bytes, int offset) { - if (object == null) { - return 0; - } - byte[] b = toBytes(object); // TODO: no byte[] allocation: use CharsetEncoder - System.arraycopy(b, 0, bytes, offset, b.length); - return b.length; - } - - @Override - public Object toObject(byte[] bytes, int offset, int length, PDataType actualType, - SortOrder sortOrder, Integer maxLength, Integer scale) { - if (!actualType.isCoercibleTo(this)) { - throwConstraintViolationException(actualType, this); - } - if (length == 0) { - return null; - } - if (sortOrder == SortOrder.DESC) { - bytes = SortOrder.invert(bytes, offset, length); - offset = 0; - } - return Bytes.toString(bytes, offset, length); - } - - @Override - public Object toObject(Object object, PDataType actualType) { - if (equalsAny(actualType, this, PChar.INSTANCE)) { - String s = (String) object; - return s == null || s.length() > 0 ? s : null; - } - return throwConstraintViolationException(actualType, this); - } - - @Override - public boolean isCoercibleTo(PDataType targetType) { - return equalsAny(targetType, this, PChar.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE); - } - - @Override - public boolean isCoercibleTo(PDataType targetType, Object value) { - if (isCoercibleTo(targetType)) { - if (targetType.equals(PChar.INSTANCE)) { - return value != null; - } - return true; - } - return false; - } - - @Override - public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType, - Integer maxLength, Integer scale, Integer desiredMaxLength, - Integer desiredScale) { - if (ptr.getLength() != 0 && maxLength != null && desiredMaxLength != null) { - return maxLength <= desiredMaxLength; - } - return true; - } - - @Override - public boolean isFixedWidth() { - return false; - } - - @Override - public int estimateByteSize(Object o) { - String value = (String) o; - return value == null ? 1 : value.length(); - } - - @Override - public Integer getByteSize() { - return null; - } - - @Override - public int compareTo(Object lhs, Object rhs, PDataType rhsType) { - return ((String) lhs).compareTo((String) rhs); - } - - @Override - public Object toObject(String value) { - return value; - } - - @Override - public boolean isBytesComparableWith(PDataType otherType) { - return super.isBytesComparableWith(otherType) || otherType == PChar.INSTANCE; - } - - @Override - public String toStringLiteral(Object o, Format formatter) { - if (formatter != null) { - return "'" + formatter.format(o) + "'"; - } - return "'" + StringUtil.escapeStringConstant(o.toString()) + "'"; - } - - private char[] sampleChars = new char[1]; - - @Override - public Object getSampleValue(Integer maxLength, Integer arrayLength) { - Preconditions.checkArgument(maxLength == null || maxLength >= 0); - int length = maxLength != null ? maxLength : 1; - if (length != sampleChars.length) { - sampleChars = new char[length]; - } - for (int i = 0; i < length; i++) { - sampleChars[i] = (char) RANDOM.get().nextInt(Byte.MAX_VALUE); - } - return new String(sampleChars); - } + public static final PVarchar INSTANCE = new PVarchar(); --- End diff -- Minor nit: indenting looks off here. Should be no tabs and 4 space chars. > Support native JSON data type > ----------------------------- > > Key: PHOENIX-628 > URL: https://issues.apache.org/jira/browse/PHOENIX-628 > Project: Phoenix > Issue Type: Task > Affects Versions: 4.4.0 > Reporter: James Taylor > Assignee: Aakash Pradeep > Labels: JSON, Java, SQL > Fix For: 4.4.0 > > > MongoDB and PostGres do some interesting things with JSON. We should look at > adding similar support. For a detailed description, see JSONB support in > Postgres: > http://www.craigkerstiens.com/2014/03/24/Postgres-9.4-Looking-up > http://www.depesz.com/2014/03/25/waiting-for-9-4-introduce-jsonb-a-structured-format-for-storing-json/ > http://michael.otacoo.com/postgresql-2/manipulating-jsonb-data-with-key-unique/ -- This message was sent by Atlassian JIRA (v6.3.4#6332)