当前位置: 首页>>代码示例>>Java>>正文


Java ValueMetaInterface.TYPE_TIMESTAMP属性代码示例

本文整理汇总了Java中org.pentaho.di.core.row.ValueMetaInterface.TYPE_TIMESTAMP属性的典型用法代码示例。如果您正苦于以下问题:Java ValueMetaInterface.TYPE_TIMESTAMP属性的具体用法?Java ValueMetaInterface.TYPE_TIMESTAMP怎么用?Java ValueMetaInterface.TYPE_TIMESTAMP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.pentaho.di.core.row.ValueMetaInterface的用法示例。


在下文中一共展示了ValueMetaInterface.TYPE_TIMESTAMP属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: messageArrived

@Override public void messageArrived( String topic, MqttMessage mqttMessage ) throws Exception {
  Object[] outRow = RowDataUtil.allocateRowData( m_data.m_outputRowMeta.size() );
  outRow[0] = topic;
  Object converted = null;

  byte[] raw = mqttMessage.getPayload();
  ByteBuffer buff = null;
  switch ( m_messageValueMeta.getType() ) {
    case ValueMetaInterface.TYPE_INTEGER:
      buff = ByteBuffer.wrap( raw );
      outRow[1] = raw.length == 4 ? (long) buff.getInt() : buff.getLong();
      break;
    case ValueMetaInterface.TYPE_STRING:
    case ValueMetaInterface.TYPE_NONE:
      outRow[1] = new String( raw );
      break;
    case ValueMetaInterface.TYPE_NUMBER:
      buff = ByteBuffer.wrap( raw );
      outRow[1] = raw.length == 4 ? (double) buff.getFloat() : buff.getDouble();
      break;
    case ValueMetaInterface.TYPE_DATE:
      buff = ByteBuffer.wrap( raw );
      outRow[1] = new Date( buff.getLong() );
      break;
    case ValueMetaInterface.TYPE_BINARY:
      outRow[1] = raw;
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      outRow[1] = raw[0] > 0;
      break;
    case ValueMetaInterface.TYPE_TIMESTAMP:
      buff = ByteBuffer.wrap( raw );
      long time = buff.getLong();
      int nanos = buff.getInt();
      Timestamp t = new Timestamp( time );
      t.setNanos( nanos );
      outRow[1] = t;
      break;
    case ValueMetaInterface.TYPE_SERIALIZABLE:
      ObjectInputStream ois = new ObjectInputStream( new ByteArrayInputStream( raw ) );
      outRow[1] = ois.readObject();
      break;
    default:
      throw new KettleException( "Unhandled type" );
  }
  putRow( m_data.m_outputRowMeta, outRow );
}
 
开发者ID:pentaho-labs,项目名称:pentaho-mqtt-plugin,代码行数:47,代码来源:MQTTSubscriber.java

示例2: messageToBytes

protected byte[] messageToBytes( Object message, ValueMetaInterface messageValueMeta ) throws KettleValueException {
  if ( message == null || Const.isEmpty( message.toString() ) ) {
    return null;
  }

  byte[] result = null;
  try {
    ByteBuffer buff = null;
    switch ( messageValueMeta.getType() ) {
      case ValueMetaInterface.TYPE_STRING:
        result = message.toString().getBytes( "UTF-8" );
        break;
      case ValueMetaInterface.TYPE_INTEGER:
      case ValueMetaInterface.TYPE_DATE: // send the date as a long (milliseconds) value
        buff = ByteBuffer.allocate( 8 );
        buff.putLong( messageValueMeta.getInteger( message ) );
        result = buff.array();
        break;
      case ValueMetaInterface.TYPE_NUMBER:
        buff = ByteBuffer.allocate( 8 );
        buff.putDouble( messageValueMeta.getNumber( message ) );
        result = buff.array();
        break;
      case ValueMetaInterface.TYPE_TIMESTAMP:
        buff = ByteBuffer.allocate( 12 );
        Timestamp ts = (Timestamp) message;
        buff.putLong( ts.getTime() );
        buff.putInt( ts.getNanos() );
        result = buff.array();
        break;
      case ValueMetaInterface.TYPE_BINARY:
        result = messageValueMeta.getBinary( message );
        break;
      case ValueMetaInterface.TYPE_BOOLEAN:
        result = new byte[1];
        if ( messageValueMeta.getBoolean( message ) ) {
          result[0] = 1;
        }
        break;
      case ValueMetaInterface.TYPE_SERIALIZABLE:
        if ( !( message instanceof Serializable ) ) {
          throw new KettleValueException( "Message value is not serializable!" );
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream( bos );
        oos.writeObject( message );
        oos.flush();
        result = bos.toByteArray();
        break;
    }
  } catch ( Exception ex ) {
    throw new KettleValueException( ex );
  }

  return result;
}
 
开发者ID:pentaho-labs,项目名称:pentaho-mqtt-plugin,代码行数:56,代码来源:MQTTPublisher.java

示例3: generateRandomRows

/**
 * Generate some random rows to send to python in the case where a single variable (data frame) is being extracted
 * and we want to try and determine the types of the output fields
 *
 * @param inputMeta incoming row meta
 * @param r         Random instance to use
 * @return a list of randomly generated rows with types matching the incoming row types.
 * @throws KettleException if a problem occurs
 */
protected static List<Object[]> generateRandomRows( RowMetaInterface inputMeta, Random r ) throws KettleException {
  List<Object[]> rows = new ArrayList<Object[]>( NUM_RANDOM_ROWS );
  // ValueMetaInterface numericVM = new ValueMeta( "num", ValueMetaInterface.TYPE_NUMBER ); //$NON-NLS-1$
  ValueMetaInterface numericVM = ValueMetaFactory.createValueMeta( "num", ValueMetaInterface.TYPE_NUMBER ); //$NON-NLS-1$

  for ( int i = 0; i < NUM_RANDOM_ROWS; i++ ) {
    Object[] currentRow = new Object[inputMeta.size()];
    for ( int j = 0; j < inputMeta.size(); j++ ) {
      ValueMetaInterface vm = inputMeta.getValueMeta( j );

      ValueMetaInterface tempVM = vm.clone();
      tempVM.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );

      Object newVal;
      double d = r.nextDouble();
      switch ( vm.getType() ) {
        case ValueMetaInterface.TYPE_NUMBER:
        case ValueMetaInterface.TYPE_INTEGER:
        case ValueMetaInterface.TYPE_BIGNUMBER:
          d *= 100.0;
          newVal = d;
          if ( vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ) {
            newVal = tempVM.convertData( numericVM, newVal );
          }
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? vm.convertData( numericVM, newVal ) :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        case ValueMetaInterface.TYPE_DATE:
          newVal = new Date( new Date().getTime() + (long) ( d * 100000 ) );
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        case ValueMetaInterface.TYPE_TIMESTAMP:
          newVal = new Timestamp( new Date().getTime() + (long) ( d * 100000 ) );
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          newVal = r.nextBoolean();
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        default:
          newVal = d < 0.5 ? "value1" : "value2";
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
      }
    }
    rows.add( currentRow );
  }
  return rows;
}
 
开发者ID:pentaho-labs,项目名称:pentaho-cpython-plugin,代码行数:66,代码来源:CPythonScriptExecutorData.java

示例4: rowsToCSV

protected static StringBuilder rowsToCSV( RowMetaInterface meta, List<Object[]> rows ) throws KettleValueException {
  StringBuilder builder = new StringBuilder();
  // header row
  int i = 0;
  for ( ValueMetaInterface v : meta.getValueMetaList() ) {
    String name = quote( v.getName() );
    builder.append( i > 0 ? "," : "" ).append( name );
    i++;
  }
  builder.append( "\n" );
  for ( Object[] row : rows ) {
    for ( i = 0; i < meta.size(); i++ ) {
      String value;
      ValueMetaInterface vm = meta.getValueMeta( i );
      if ( row[i] == null || Const.isEmpty( vm.getString( row[i] ) ) ) {
        value = "?";
      } else {
        //switch ( meta.getValueMetaList().get( i ).getType() ) {
        switch ( vm.getType() ) {
          case ValueMetaInterface.TYPE_NUMBER:
          case ValueMetaInterface.TYPE_INTEGER:
          case ValueMetaInterface.TYPE_BIGNUMBER:
            value = vm.getString( row[i] );
            break;
          case ValueMetaInterface.TYPE_DATE:
            int offset = TZ.getOffset( vm.getDate( row[i] ).getTime() );
            value = "" + ( vm.getDate( row[i] ).getTime() + offset );
            break;
          case ValueMetaInterface.TYPE_TIMESTAMP:
            offset = TZ.getOffset( vm.getDate( row[i] ).getTime() );
            value = "" + ( vm.getDate( row[i] ).getTime() + offset );
            break;
          case ValueMetaInterface.TYPE_BOOLEAN:
            value = "" + ( vm.getBoolean( row[i] ) ? "1" : "0" );
            break;
          // TODO throw an exception for Serializable/Binary
          default:
            value = quote( vm.getString( row[i] ) );
        }
      }
      builder.append( i > 0 ? "," : "" ).append( value );
    }
    builder.append( "\n" );
  }

  return builder;
}
 
开发者ID:pentaho-labs,项目名称:pentaho-cpython-plugin,代码行数:47,代码来源:ServerUtils.java

示例5: getFieldDefinition

@Override
public String getFieldDefinition(ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr) {
    String retval = "";

    int length = v.getLength();
    int precision = v.getPrecision();

    String fieldname = v.getName();
    if (add_fieldname) {
        retval += fieldname + " ";
    }

    int type = v.getType();
    switch (type) {
        case ValueMetaInterface.TYPE_INTEGER:
        case ValueMetaInterface.TYPE_NUMBER:
        case ValueMetaInterface.TYPE_BIGNUMBER:
            if (fieldname.equalsIgnoreCase(tk)) {
                retval += "BIGINT";
                if (use_autoinc) {
                    retval += " GENERATED ALWAYS AS IDENTITY";
                }
                if (fieldname.equalsIgnoreCase(pk)) {
                    retval += " PRIMARY KEY";
                }
            } else {
                if (precision == 0) {
                    if (length > 18) {
                        retval += "DECIMAL(" + length + ",0)";
                    } else {
                        if (length > 9) {
                            retval += "BIGINT";
                        } else {
                            retval += "INTEGER";
                        }
                        if (fieldname.equalsIgnoreCase(pk)) {
                            retval += " PRIMARY KEY";
                        }
                    }
                } else {
                    if (length > 15) {
                        retval += "DECIMAL(" + length;
                        if (precision > 0) {
                            retval += ", " + precision;
                        }
                        retval += ")";
                    } else {
                        retval += "DOUBLE";
                    }
                }
            }
            break;
        case ValueMetaInterface.TYPE_STRING:
            retval += "STRING";
            break;
        case ValueMetaInterface.TYPE_DATE:
            retval += "DATE";
            break;
        case ValueMetaInterface.TYPE_BOOLEAN:
            retval += "BOOLEAN";
            break;
        case ValueMetaInterface.TYPE_BINARY:
            retval += "BLOB";
            break;
        case ValueMetaInterface.TYPE_TIMESTAMP:
            retval += "TIMESTAMP";
            break;
        default:
            retval += "UNKNOWN";
            break;
    }

    if (add_cr) {
        retval += Const.CR;
    }

    return retval;
}
 
开发者ID:nuodb,项目名称:pdi-nuodb-plugin,代码行数:78,代码来源:NuoDBDatabaseMeta.java


注:本文中的org.pentaho.di.core.row.ValueMetaInterface.TYPE_TIMESTAMP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。