Package org.apache.phoenix.schema

Examples of org.apache.phoenix.schema.PDataType


    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
        Expression expression = getExpression();
        if (!expression.evaluate(tuple, ptr)) {
            return false;
        }
        PDataType type = expression.getDataType();
        Object value = formatter.format(type.toObject(ptr, expression.getSortOrder()));
        byte[] b = getDataType().toBytes(value);
        ptr.set(b);
        return true;
     }
View Full Code Here


            return false;
        } else if (ptr.getLength() == 0) {
            return true;
        }

        PDataType type = expression.getDataType();
        if (type.isCoercibleTo(PDataType.TIMESTAMP)) {
          Date date = (Date) type.toObject(ptr, expression.getSortOrder());
          BigDecimal time = new BigDecimal(date.getTime());
            byte[] byteValue = getDataType().toBytes(time);
            ptr.set(byteValue);
            return true;
        }
       
        String stringValue = (String)type.toObject(ptr, expression.getSortOrder());
        if (stringValue == null) {
            ptr.set(EMPTY_BYTE_ARRAY);
            return true;
        }
        stringValue = stringValue.trim();
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

          }
            ResourceFieldSchema fields[] = new ResourceFieldSchema[columns.size()];
            int i = 0;
            for(ColumnInfo cinfo : columns) {
                int sqlType = cinfo.getSqlType();
                PDataType phoenixDataType = PDataType.fromTypeId(sqlType);
                byte pigType = TypeUtil.getPigDataTypeForPhoenixType(phoenixDataType);
                ResourceFieldSchema field = new ResourceFieldSchema();
                field.setType(pigType).setName(cinfo.getDisplayName());
                fields[i++] = field;
            }
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

        return stmt.executeQuery();
    }
   
   
    private static void coerceDataValueToIndexValue(PColumn dataColumn, PColumn indexColumn, ImmutableBytesWritable ptr) {
        PDataType dataType = dataColumn.getDataType();
        // TODO: push to RowKeySchema?
        SortOrder dataModifier = dataColumn.getSortOrder();
        PDataType indexType = indexColumn.getDataType();
        SortOrder indexModifier = indexColumn.getSortOrder();
        // We know ordinal position will match pk position, because you cannot
        // alter an index table.
        indexType.coerceBytes(ptr, dataType, dataModifier, indexModifier);
    }
View Full Code Here

    @Override
    public boolean getBoolean(int columnIndex) throws SQLException {
        checkCursorState();
        ColumnProjector colProjector = rowProjector.getColumnProjector(columnIndex-1);
        PDataType type = colProjector.getExpression().getDataType();
        Object value = colProjector.getValue(currentRow, type, ptr);
        wasNull = (value == null);
        if (value == null) {
            return false;
        }
View Full Code Here

    public String getString(int columnIndex) throws SQLException {
        checkCursorState();
        // Get the value using the expected type instead of trying to coerce to VARCHAR.
        // We can't coerce using our formatter because we don't have enough context in PDataType.
        ColumnProjector projector = rowProjector.getColumnProjector(columnIndex-1);
        PDataType type = projector.getExpression().getDataType();
        Object value = projector.getValue(currentRow,type, ptr);
        if (wasNull = (value == null)) {
            return null;
        }
        // Run Object through formatter to get String.
View Full Code Here

        parameters.set(parameterIndex - 1, o);
    }

    @Override
    public void setObject(int parameterIndex, Object o, int targetSqlType) throws SQLException {
        PDataType targetType = PDataType.fromSqlType(targetSqlType);
        PDataType sourceType = PDataType.fromLiteral(o);
        o = targetType.toObject(o, sourceType);
        parameters.set(parameterIndex - 1, o);
    }
View Full Code Here

TOP

Related Classes of org.apache.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.