Package com.salesforce.phoenix.schema

Examples of com.salesforce.phoenix.schema.PDataType


    private ImmutableBytesPtr value = new ImmutableBytesPtr();
    private List<Expression> keyExpressions; // client side only

    public static Expression create (List<Expression> children, ImmutableBytesWritable ptr) throws SQLException {
        Expression firstChild = children.get(0);
        PDataType firstChildType = firstChild.getDataType();
       
        boolean addedNull = false;
        List<Expression> keys = Lists.newArrayListWithExpectedSize(children.size());
        List<Expression> coercedKeyExpressions = Lists.newArrayListWithExpectedSize(children.size());
        keys.add(firstChild);
        coercedKeyExpressions.add(firstChild);
        for (int i = 1; i < children.size(); i++) {
            Expression rhs = children.get(i);
            if (rhs.evaluate(null, ptr)) {
                if (ptr.getLength() == 0) {
                    if (!addedNull) {
                        addedNull = true;
                        keys.add(LiteralExpression.newConstant(null, PDataType.VARBINARY, true));
                        coercedKeyExpressions.add(LiteralExpression.newConstant(null, firstChildType, true));
                    }
                } else {
                    // Don't specify the firstChild column modifier here, as we specify it in the LiteralExpression creation below
                    try {
                        firstChildType.coerceBytes(ptr, rhs.getDataType(), rhs.getColumnModifier(), null);
                        keys.add(LiteralExpression.newConstant(ByteUtil.copyKeyBytesIfNecessary(ptr), PDataType.VARBINARY, firstChild.getColumnModifier(), true));
                        if(rhs.getDataType() == firstChildType) {
                            coercedKeyExpressions.add(rhs);
                        } else {
                            coercedKeyExpressions.add(CoerceExpression.create(rhs, firstChildType));   
View Full Code Here


    @Override
    public String toString() {
        int maxToStringLen = 200;
        Expression firstChild = children.get(0);
        PDataType type = firstChild.getDataType();
        StringBuilder buf = new StringBuilder(firstChild + " IN (");
        if (containsNull) {
            buf.append("null,");
        }
        for (ImmutableBytesPtr value : values) {
            if (firstChild.getColumnModifier() != null) {
                type.coerceBytes(value, type, firstChild.getColumnModifier(), null);
            }
            buf.append(type.toStringLiteral(value, null));
            buf.append(',');
            if (buf.length() >= maxToStringLen) {
                buf.append("... ");
                break;
            }
View Full Code Here

  public static PDataType getType(Object obj, byte type) {
    if (obj == null) {
      return null;
    }
 
    PDataType sqlType;

    switch (type) {
    case DataType.BYTEARRAY:
      sqlType = PDataType.VARBINARY;
      break;
View Full Code Here

   * @param o
   * @param targetPhoenixType
   * @return Object
   */
  public static Object castPigTypeToPhoenix(Object o, byte objectType, PDataType targetPhoenixType) {
    PDataType inferredPType = getType(o, objectType);
   
    if(inferredPType == null) {
      return null;
    }
   
    if(inferredPType == PDataType.VARBINARY && targetPhoenixType != PDataType.VARBINARY) {
      try {
        o = castBytes(o, targetPhoenixType);
        inferredPType = getType(o, DataType.findType(o));
      } catch (IOException e) {
        throw new RuntimeException("Error while casting bytes for object " +o);
      }
    }

    if(inferredPType == PDataType.DATE) {
      int inferredSqlType = targetPhoenixType.getSqlType();

      if(inferredSqlType == Types.DATE) {
        return new Date(((DateTime)o).getMillis());
      }
      if(inferredSqlType == Types.TIME) {
        return new Time(((DateTime)o).getMillis());
      }
      if(inferredSqlType == Types.TIMESTAMP) {
        return new Timestamp(((DateTime)o).getMillis());
      }
    }
   
    if (targetPhoenixType == inferredPType || inferredPType.isCoercibleTo(targetPhoenixType)) {
      return inferredPType.toObject(o, targetPhoenixType);
    }
   
    throw new RuntimeException(o.getClass().getName()
        + " cannot be coerced to "+targetPhoenixType.toString());
  }
View Full Code Here

  public void add(Object value) {
    values.add(value);
  }

  private Object convertTypeSpecificValue(Object o, byte type, Integer sqlType) {
    PDataType pDataType = PDataType.fromTypeId(sqlType);

    return TypeUtil.castPigTypeToPhoenix(o, type, pDataType);
  }
View Full Code Here

        if (range.length == 0) {
            buf.append('*');
            return;
        }
        ScanRanges scanRanges = context.getScanRanges();
        PDataType type = scanRanges.getSchema().getField(slotIndex).getDataType();
        ColumnModifier modifier = tableRef.getTable().getPKColumns().get(slotIndex).getColumnModifier();
        if (modifier != null) {
            buf.append('~');
            range = modifier.apply(range, 0, new byte[range.length], 0, range.length);
        }
        Format formatter = context.getConnection().getFormatter(type);
        buf.append(type.toStringLiteral(range, formatter));
    }
View Full Code Here

        super(name, children, info);
    }

    @Override
    public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
        PDataType dataType = children.get(0).getDataType();
        String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
        Format formatter =  null;
        FunctionArgumentType type;
       
        if (dataType.isCoercibleTo(PDataType.TIMESTAMP)) {
            if (formatString == null) {
                formatString = context.getDateFormat();
                formatter = context.getDateFormatter();
            } else {
                formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
            }
            type = FunctionArgumentType.TEMPORAL;
        }
        else if (dataType.isCoercibleTo(PDataType.CHAR)) {
            if (formatString != null) {
                formatter = FunctionArgumentType.CHAR.getFormatter(formatString);
            }
            type = FunctionArgumentType.CHAR;
        }
View Full Code Here

            }
            BitSet descIndexColumnBitSet = rowKeyMetaData.getDescIndexColumnBitSet();
            int j = 0;
            Iterator<ColumnReference> iterator = indexedColumns.iterator();
            for (int i = 0; i < nIndexedColumns; i++) {
                PDataType dataColumnType;
                boolean isNullable = true;
                boolean isDataColumnInverted = false;
                ColumnModifier dataColumnModifier = null;
                if (dataPkPosition[i] == -1) {
                    dataColumnType = indexedColumnTypes.get(j);
                    ImmutableBytesPtr value = valueGetter.getLatestValue(iterator.next());
                    if (value == null) {
                        ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
                    } else {
                        ptr.set(value.copyBytesIfNecessary());
                    }
                    j++;
               } else {
                   Field field = dataRowKeySchema.getField(dataPkPosition[i]);
                    dataColumnType = field.getDataType();
                    ptr.set(rowKeyPtr.get(), dataRowKeyLocator[0][i], dataRowKeyLocator[1][i]);
                    dataColumnModifier = field.getColumnModifier();
                    isDataColumnInverted = dataColumnModifier != null;
                    isNullable = field.isNullable();
                }
                PDataType indexColumnType = IndexUtil.getIndexColumnDataType(isNullable, dataColumnType);
                boolean isBytesComparable = dataColumnType.isBytesComparableWith(indexColumnType) ;
                if (isBytesComparable && isDataColumnInverted == descIndexColumnBitSet.get(i)) {
                    output.write(ptr.get(), ptr.getOffset(), ptr.getLength());
                } else {
                    if (!isBytesComparable)  {
                        indexColumnType.coerceBytes(ptr, dataColumnType, dataColumnModifier, null);
                    }
                    if (descIndexColumnBitSet.get(i) != isDataColumnInverted) {
                        writeInverted(ptr.get(), ptr.getOffset(), ptr.getLength(), output);
                    } else {
                        output.write(ptr.get(), ptr.getOffset(), ptr.getLength());
                    }
                }
                if (!indexColumnType.isFixedWidth()) {
                    output.writeByte(QueryConstants.SEPARATOR_BYTE);
                }
            }
            int length = stream.size();
            int minLength = length - maxTrailingNulls;
View Full Code Here

            byte[] cq = Bytes.readByteArray(input);
            indexedColumns.add(new ColumnReference(cf,cq));
        }
        indexedColumnTypes = Lists.newArrayListWithExpectedSize(nIndexedColumns);
        for (int i = 0; i < nIndexedColumns; i++) {
            PDataType type = PDataType.values()[WritableUtils.readVInt(input)];
            indexedColumnTypes.add(type);
        }
        indexedColumnByteSizes = Lists.newArrayListWithExpectedSize(nIndexedColumns);
        for (int i = 0; i < nIndexedColumns; i++) {
            int byteSize = WritableUtils.readVInt(input);
View Full Code Here

        for (ColumnReference ref : indexedColumns) {
            Bytes.writeByteArray(output, ref.getFamily());
            Bytes.writeByteArray(output, ref.getQualifier());
        }
        for (int i = 0; i < indexedColumnTypes.size(); i++) {
            PDataType type = indexedColumnTypes.get(i);
            WritableUtils.writeVInt(output, type.ordinal());
        }
        for (int i = 0; i < indexedColumnByteSizes.size(); i++) {
            Integer byteSize = indexedColumnByteSizes.get(i);
            WritableUtils.writeVInt(output, byteSize == null ? 0 : byteSize);
        }
View Full Code Here

TOP

Related Classes of com.salesforce.phoenix.schema.PDataType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.