Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#TYPE_BOOLEAN

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#TYPE_BOOLEAN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowForumulaContext.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static Object getPrimitive( ValueMetaInterface valueMeta, Object valueData ) throws KettleValueException {
  switch ( valueMeta.getType() ) {
    case ValueMetaInterface.TYPE_BIGNUMBER:
      return valueMeta.getBigNumber( valueData );
    case ValueMetaInterface.TYPE_BINARY:
      return valueMeta.getBinary( valueData );
    case ValueMetaInterface.TYPE_BOOLEAN:
      return valueMeta.getBoolean( valueData );
    case ValueMetaInterface.TYPE_DATE:
      return valueMeta.getDate( valueData );
    case ValueMetaInterface.TYPE_INTEGER:
      return valueMeta.getInteger( valueData );
    case ValueMetaInterface.TYPE_NUMBER:
      return valueMeta.getNumber( valueData );
      // case ValueMetaInterface.TYPE_SERIALIZABLE: return valueMeta.(valueData);
    case ValueMetaInterface.TYPE_STRING:
      return valueMeta.getString( valueData );
    default:
      return null;
  }
}
 
Example 2
Source File: YamlReader.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private int getType( Object value ) {

    if ( value instanceof Integer ) {
      return ValueMetaInterface.TYPE_INTEGER;
    }
    if ( value instanceof Double ) {
      return ValueMetaInterface.TYPE_NUMBER;
    } else if ( value instanceof Long ) {
      return ValueMetaInterface.TYPE_INTEGER;
    } else if ( value instanceof Date ) {
      return ValueMetaInterface.TYPE_DATE;
    } else if ( value instanceof java.sql.Date ) {
      return ValueMetaInterface.TYPE_DATE;
    } else if ( value instanceof Timestamp ) {
      return ValueMetaInterface.TYPE_DATE;
    } else if ( value instanceof Boolean ) {
      return ValueMetaInterface.TYPE_BOOLEAN;
    } else if ( value instanceof BigInteger ) {
      return ValueMetaInterface.TYPE_BIGNUMBER;
    } else if ( value instanceof BigDecimal ) {
      return ValueMetaInterface.TYPE_BIGNUMBER;
    } else if ( value instanceof Byte ) {
      return ValueMetaInterface.TYPE_BINARY;
    }
    return ValueMetaInterface.TYPE_STRING;
  }
 
Example 3
Source File: CassandraColumnMetaData.java    From learning-hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Return the Cassandra CQL column/key type for the given Kettle column. We
 * use this type for CQL create column family statements since, for some
 * reason, the internal type isn't recognized for the key. Internal types
 * *are* recognized for column definitions. The CQL reference guide states
 * that fully qualified (or relative to org.apache.cassandra.db.marshal) class
 * names can be used instead of CQL types - however, using these when defining
 * the key type always results in BytesType getting set for the key for some
 * reason.
 * 
 * @param vm the ValueMetaInterface for the Kettle column
 * @return the corresponding CQL type
 */
public static String getCQLTypeForValueMeta(ValueMetaInterface vm) {
  switch (vm.getType()) {
  case ValueMetaInterface.TYPE_STRING:
    return "varchar";
  case ValueMetaInterface.TYPE_BIGNUMBER:
    return "decimal";
  case ValueMetaInterface.TYPE_BOOLEAN:
    return "boolean";
  case ValueMetaInterface.TYPE_INTEGER:
    return "bigint";
  case ValueMetaInterface.TYPE_NUMBER:
    return "double";
  case ValueMetaInterface.TYPE_DATE:
    return "timestamp";
  case ValueMetaInterface.TYPE_BINARY:
  case ValueMetaInterface.TYPE_SERIALIZABLE:
    return "blob";
  }

  return "blob";
}
 
Example 4
Source File: CommonHadoopShim.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
@Override
public Class<? extends Writable> getHadoopWritableCompatibleClass( ValueMetaInterface kettleType ) {
  if ( kettleType == null ) {
    return NullWritable.class;
  }
  switch ( kettleType.getType() ) {
    case ValueMetaInterface.TYPE_STRING:
    case ValueMetaInterface.TYPE_BIGNUMBER:
    case ValueMetaInterface.TYPE_DATE:
      return Text.class;
    case ValueMetaInterface.TYPE_INTEGER:
      return LongWritable.class;
    case ValueMetaInterface.TYPE_NUMBER:
      return DoubleWritable.class;
    case ValueMetaInterface.TYPE_BOOLEAN:
      return BooleanWritable.class;
    case ValueMetaInterface.TYPE_BINARY:
      return BytesWritable.class;
    default:
      return Text.class;
  }
}
 
Example 5
Source File: PentahoOrcRecordWriter.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
private ValueMetaInterface getValueMetaInterface( String fieldName, int fieldType ) {
  switch ( fieldType ) {
    case ValueMetaInterface.TYPE_INET:
      return new ValueMetaInternetAddress( fieldName );
    case ValueMetaInterface.TYPE_STRING:
      return new ValueMetaString( fieldName );
    case ValueMetaInterface.TYPE_INTEGER:
      return new ValueMetaInteger( fieldName );
    case ValueMetaInterface.TYPE_NUMBER:
      return new ValueMetaNumber( fieldName );
    case ValueMetaInterface.TYPE_BIGNUMBER:
      return new ValueMetaBigNumber( fieldName );
    case ValueMetaInterface.TYPE_TIMESTAMP:
      return new ValueMetaTimestamp( fieldName );
    case ValueMetaInterface.TYPE_DATE:
      return new ValueMetaDate( fieldName );
    case ValueMetaInterface.TYPE_BOOLEAN:
      return new ValueMetaBoolean( fieldName );
    case ValueMetaInterface.TYPE_BINARY:
      return new ValueMetaBinary( fieldName );
  }
  return null;
}
 
Example 6
Source File: ValueMetaConverter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected Object convertFromBooleanMetaInterface( int targetValueMetaType, Object value )
  throws ValueMetaConversionException {

  if ( value == null ) {
    return null;
  }

  if ( !( value instanceof Boolean ) ) {
    handleConversionError(
      "Error.  Expecting value of type Boolean.    actual value type = '" + value.getClass() + "'.    value = '"
        + value + "'." );
  }

  try {
    switch ( targetValueMetaType ) {
      case ValueMetaInterface.TYPE_STRING:
        return Boolean.toString( (Boolean) value );
      case ValueMetaInterface.TYPE_BOOLEAN:
        return new Boolean( (Boolean) value );
      default:
        throwBadConversionCombination( ValueMetaInterface.TYPE_BOOLEAN, targetValueMetaType, value );
    }
  } catch ( Exception e ) {
    throwErroredConversion( ValueMetaInterface.TYPE_BOOLEAN, targetValueMetaType, value, e );
  }

  return null;
}
 
Example 7
Source File: StepInjectionUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static StepInjectionMetaEntry getEntry( StepMetaInjectionEntryInterface entryInterface, Object value ) {
  StepInjectionMetaEntry entry = new StepInjectionMetaEntry(
    entryInterface.name(),
    entryInterface.getValueType(),
    entryInterface.getDescription() );

  // If the value is null, leave it alone.
  //
  if ( value == null ) {
    return entry;
  }
  switch ( entryInterface.getValueType() ) {
    case ValueMetaInteger.TYPE_STRING:
      if ( value instanceof Boolean ) {
        entry.setValue( ( (Boolean) value ) ? "Y" : "N" );
      } else {
        entry.setValue( value.toString() );
      }
      break;
    case ValueMetaInterface.TYPE_INTEGER:
      entry.setValue( Long.valueOf( value.toString() ) );
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      entry.setValue( "Y".equalsIgnoreCase( value.toString() )
        || "TRUE".equalsIgnoreCase( value.toString() ) );
      break;
    case ValueMetaInterface.TYPE_NONE:
      break;
    default:
      entry.setValue( value );
      break;
  }
  return entry;
}
 
Example 8
Source File: AvroToPdiConverter.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
private Object convertToPentahoType( int pentahoType, Boolean avroData ) {
  Object pentahoData = null;
  if ( avroData != null ) {
    try {
      switch ( pentahoType ) {
        case ValueMetaInterface.TYPE_STRING:
          pentahoData = avroData.toString();
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          pentahoData = avroData;
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          pentahoData = avroData ? new Long( 1 ) : new Long( 0 );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          pentahoData = avroData ? new Double( 1 ) : new Double( 0 );
          break;
        case ValueMetaInterface.TYPE_BIGNUMBER:
          pentahoData = avroData ? new BigDecimal( 1 ) : new BigDecimal( 0 );
          break;
      }
    } catch ( Exception e ) {
      // If unable to do the type conversion just ignore. null will be returned.
    }
  }
  return pentahoData;
}
 
Example 9
Source File: CiviStep.java    From civicrm-data-integration with GNU General Public License v3.0 5 votes vote down vote up
protected Object getObjectValue(String field, String object) {
    try {
        if (object == null || object.equals("")) {
            return null;
        }

        CiviField cf = ((CiviMeta) civiMeta).getCiviCrmListingFields().get(field);

        int metaType =  ValueMetaInterface.TYPE_STRING;
        if (cf != null)
           metaType = cf.getMetaInterfaceType();

        switch (metaType) {
        case ValueMetaInterface.TYPE_INTEGER:
            return Long.parseLong(object);
        case ValueMetaInterface.TYPE_STRING:
            return object.toString();
        case ValueMetaInterface.TYPE_NUMBER:
            return Double.parseDouble(object);
        case ValueMetaInterface.TYPE_DATE:
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            return formatter.parse(object);
        case ValueMetaInterface.TYPE_BIGNUMBER:
            return new BigDecimal(object.toString());
        case ValueMetaInterface.TYPE_BOOLEAN:
            return Boolean.parseBoolean(object);
        case ValueMetaInterface.TYPE_BINARY:
            throw new KettleValueException(toString() + " : I don't know how to convert binary values to integers.");
        case ValueMetaInterface.TYPE_SERIALIZABLE:
            throw new KettleValueException(toString()
                    + " : I don't know how to convert serializable values to integers.");
        default:
            throw new KettleValueException(toString() + " : Unknown type " + metaType + " specified.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 10
Source File: FieldHelper.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static String getGetSignature( String accessor, ValueMetaInterface v ) {
  StringBuilder sb = new StringBuilder();

  switch ( v.getType() ) {
    case ValueMetaInterface.TYPE_BIGNUMBER:
      sb.append( "BigDecimal " );
      break;
    case ValueMetaInterface.TYPE_BINARY:
      sb.append( "byte[] " );
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      sb.append( "Boolean " );
      break;
    case ValueMetaInterface.TYPE_DATE:
      sb.append( "Date " );
      break;
    case ValueMetaInterface.TYPE_INTEGER:
      sb.append( "Long " );
      break;
    case ValueMetaInterface.TYPE_NUMBER:
      sb.append( "Double " );
      break;
    case ValueMetaInterface.TYPE_STRING:
      sb.append( "String " );
      break;
    case ValueMetaInterface.TYPE_INET:
      sb.append( "InetAddress " );
      break;
    case ValueMetaInterface.TYPE_TIMESTAMP:
      sb.append( "Timestamp " );
      break;
    case ValueMetaInterface.TYPE_SERIALIZABLE:
    default:
      sb.append( "Object " );
      break;
  }

  if ( validJavaIdentifier.matcher( v.getName() ).matches() ) {
    sb.append( v.getName() );
  } else {
    sb.append( "value" );
  }
  String name = getNativeDataTypeSimpleName( v );
  sb
    .append( " = " ).append( accessor ).append( ".get" ).append( "-".equals( name ) ? "Object" : name )
    .append( "(r);" );

  return sb.toString();
}
 
Example 11
Source File: MonetDBBulkLoaderMetaTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testInjection() {

  try {
    List<StepInjectionMetaEntry> entries =
        loader.getStepMeta().getStepMetaInterface().getStepMetaInjectionInterface().getStepInjectionMetadataEntries();

    for ( StepInjectionMetaEntry entry : entries ) {
      entry.setValueType( lm.findAttribute( entry.getKey() ).getType() );
      switch ( entry.getValueType() ) {
        case ValueMetaInterface.TYPE_STRING:
          entry.setValue( "new_".concat( entry.getKey() ) );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          entry.setValue( Boolean.TRUE );
          break;
        default:
          break;
      }

      if ( !entry.getDetails().isEmpty() ) {

        List<StepInjectionMetaEntry> childEntries = entry.getDetails().get( 0 ).getDetails();
        for ( StepInjectionMetaEntry childEntry : childEntries ) {
          switch ( childEntry.getValueType() ) {
            case ValueMetaInterface.TYPE_STRING:
              childEntry.setValue( "new_".concat( childEntry.getKey() ) );
              break;
            case ValueMetaInterface.TYPE_BOOLEAN:
              childEntry.setValue( Boolean.TRUE );
              break;
            default:
              break;
          }
        }

      }

    }

    loader.getStepMeta().getStepMetaInterface().getStepMetaInjectionInterface().injectStepMetadataEntries( entries );

    assertEquals( "Schema name not properly injected... ", "new_SCHEMA", lm.getSchemaName() );
    assertEquals( "Table name not properly injected... ", "new_TABLE", lm.getTableName() );
    assertEquals( "Logfile not properly injected... ", "new_LOGFILE", lm.getLogFile() );
    assertEquals( "Field separator not properly injected... ", "new_FIELD_SEPARATOR", lm.getFieldSeparator() );
    assertEquals( "Field enclosure not properly injected... ", "new_FIELD_ENCLOSURE", lm.getFieldEnclosure() );
    assertEquals( "Null representation not properly injected... ", "new_NULL_REPRESENTATION", lm.getNULLrepresentation() );
    assertEquals( "Encoding path not properly injected... ", "new_ENCODING", lm.getEncoding() );
    assertEquals( "Buffer size not properly injected... ", "new_BUFFER_SIZE", lm.getBufferSize() );
    assertEquals( "Truncate not properly injected... ", Boolean.TRUE, lm.isTruncate() );
    assertEquals( "Fully Quote SQL not properly injected... ", Boolean.TRUE, lm.isFullyQuoteSQL() );

    assertEquals( "Field name not properly injected... ", "new_FIELDNAME", lm.getFieldTable()[0] );
    assertEquals( "Stream name not properly injected... ", "new_STREAMNAME", lm.getFieldStream()[0] );
    assertEquals( "Field Format not properly injected... ", Boolean.TRUE, lm.getFieldFormatOk()[0] );

  } catch ( KettleException e ) {
    fail( e.getMessage() );
  }

}
 
Example 12
Source File: ValueMetaBaseTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetValueFromNode() throws Exception {

  ValueMetaBase valueMetaBase = null;
  Node xmlNode = null;

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_STRING );
  xmlNode = XMLHandler.loadXMLString( "<value-data>String val</value-data>" ).getFirstChild();
  assertEquals( "String val", valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_NUMBER );
  xmlNode = XMLHandler.loadXMLString( "<value-data>689.2</value-data>" ).getFirstChild();
  assertEquals( 689.2, valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_NUMBER );
  xmlNode = XMLHandler.loadXMLString( "<value-data>689.2</value-data>" ).getFirstChild();
  assertEquals( 689.2, valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_INTEGER );
  xmlNode = XMLHandler.loadXMLString( "<value-data>68933</value-data>" ).getFirstChild();
  assertEquals( 68933l, valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_DATE );
  xmlNode = XMLHandler.loadXMLString( "<value-data>2017/11/27 08:47:10.000</value-data>" ).getFirstChild();
  assertEquals( XMLHandler.stringToDate( "2017/11/27 08:47:10.000" ), valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_TIMESTAMP );
  xmlNode = XMLHandler.loadXMLString( "<value-data>2017/11/27 08:47:10.123456789</value-data>" ).getFirstChild();
  assertEquals( XMLHandler.stringToTimestamp( "2017/11/27 08:47:10.123456789" ), valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_BOOLEAN );
  xmlNode = XMLHandler.loadXMLString( "<value-data>Y</value-data>" ).getFirstChild();
  assertEquals( true, valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_BINARY );
  byte[] bytes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  String s = XMLHandler.encodeBinaryData( bytes );
  xmlNode = XMLHandler.loadXMLString( "<value-data>test<binary-value>" + s + "</binary-value></value-data>" ).getFirstChild();
  assertArrayEquals( bytes, (byte[]) valueMetaBase.getValue( xmlNode ) );

  valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_STRING );
  xmlNode = XMLHandler.loadXMLString( "<value-data></value-data>" ).getFirstChild();
  assertNull( valueMetaBase.getValue( xmlNode ) );
}
 
Example 13
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Clones the data. Normally, we don't have to do anything here, but just for arguments and safety, we do a little
 * extra work in case of binary blobs and Date objects. We should write a programmers manual later on to specify in
 * all clarity that "we always overwrite/replace values in the Object[] data rows, we never modify them" .
 *
 * @return a cloned data object if needed
 */
@Override
public Object cloneValueData( Object object ) throws KettleValueException {
  if ( object == null ) {
    return null;
  }

  if ( storageType == STORAGE_TYPE_NORMAL ) {
    switch ( getType() ) {
      case ValueMetaInterface.TYPE_STRING:
      case ValueMetaInterface.TYPE_NUMBER:
      case ValueMetaInterface.TYPE_INTEGER:
      case ValueMetaInterface.TYPE_BOOLEAN:
      case ValueMetaInterface.TYPE_BIGNUMBER: // primitive data types: we can only
        // overwrite these, not change them
        return object;

      case ValueMetaInterface.TYPE_DATE:
        return new Date( ( (Date) object ).getTime() ); // just to make sure: very
        // inexpensive too.

      case ValueMetaInterface.TYPE_BINARY:
        byte[] origin = (byte[]) object;
        byte[] target = new byte[origin.length];
        System.arraycopy( origin, 0, target, 0, origin.length );
        return target;

      case ValueMetaInterface.TYPE_SERIALIZABLE:
        // Let's not create a copy but simply return the same value.
        //
        return object;

      default:
        throw new KettleValueException( toString() + ": unable to make copy of value type: " + getType() );
    }
  } else {

    return object;

  }
}
 
Example 14
Source File: TeraFast.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Write a single row to the temporary data file.
 *
 * @param rowMetaInterface
 *          describe the row of data
 *
 * @param row
 *          row entries
 * @throws KettleException
 *           ...
 */
@SuppressWarnings( "ArrayToString" )
public void writeToDataFile( RowMetaInterface rowMetaInterface, Object[] row ) throws KettleException {
  // Write the data to the output
  ValueMetaInterface valueMeta = null;

  for ( int i = 0; i < row.length; i++ ) {
    if ( row[i] == null ) {
      break; // no more rows
    }
    valueMeta = rowMetaInterface.getValueMeta( i );
    if ( row[i] != null ) {
      switch ( valueMeta.getType() ) {
        case ValueMetaInterface.TYPE_STRING:
          String s = rowMetaInterface.getString( row, i );
          dataFilePrintStream.print( pad( valueMeta, s.toString() ) );
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          Long l = rowMetaInterface.getInteger( row, i );
          dataFilePrintStream.print( pad( valueMeta, l.toString() ) );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          Double d = rowMetaInterface.getNumber( row, i );
          dataFilePrintStream.print( pad( valueMeta, d.toString() ) );
          break;
        case ValueMetaInterface.TYPE_BIGNUMBER:
          BigDecimal bd = rowMetaInterface.getBigNumber( row, i );
          dataFilePrintStream.print( pad( valueMeta, bd.toString() ) );
          break;
        case ValueMetaInterface.TYPE_DATE:
          Date dt = rowMetaInterface.getDate( row, i );
          dataFilePrintStream.print( simpleDateFormat.format( dt ) );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          Boolean b = rowMetaInterface.getBoolean( row, i );
          if ( b.booleanValue() ) {
            dataFilePrintStream.print( "Y" );
          } else {
            dataFilePrintStream.print( "N" );
          }
          break;
        case ValueMetaInterface.TYPE_BINARY:
          byte[] byt = rowMetaInterface.getBinary( row, i );
          // REVIEW - this does an implicit byt.toString, which can't be what was intended.
          dataFilePrintStream.print( byt );
          break;
        default:
          throw new KettleException( BaseMessages.getString(
            PKG, "TeraFast.Exception.TypeNotSupported", valueMeta.getType() ) );
      }
    }
    dataFilePrintStream.print( FastloadControlBuilder.DATAFILE_COLUMN_SEPERATOR );
  }
  dataFilePrintStream.print( Const.CR );
}
 
Example 15
Source File: OrcConverter.java    From pentaho-hadoop-shims with Apache License 2.0 4 votes vote down vote up
protected static Object convertFromSourceToTargetDataType( ColumnVector columnVector, int currentBatchRow,
                                                           int orcValueMetaInterface ) {

  if ( columnVector.isNull[ currentBatchRow ] ) {
    return null;
  }
  switch ( orcValueMetaInterface ) {
    case ValueMetaInterface.TYPE_INET:
      try {
        return InetAddress.getByName( new String( ( (BytesColumnVector) columnVector ).vector[ currentBatchRow ],
          ( (BytesColumnVector) columnVector ).start[ currentBatchRow ],
          ( (BytesColumnVector) columnVector ).length[ currentBatchRow ] ) );
      } catch ( UnknownHostException e ) {
        e.printStackTrace();
      }

    case ValueMetaInterface.TYPE_STRING:
      return new String( ( (BytesColumnVector) columnVector ).vector[ currentBatchRow ],
        ( (BytesColumnVector) columnVector ).start[ currentBatchRow ],
        ( (BytesColumnVector) columnVector ).length[ currentBatchRow ] );

    case ValueMetaInterface.TYPE_INTEGER:
      return (long) ( (LongColumnVector) columnVector ).vector[ currentBatchRow ];

    case ValueMetaInterface.TYPE_NUMBER:
      return ( (DoubleColumnVector) columnVector ).vector[ currentBatchRow ];

    case ValueMetaInterface.TYPE_BIGNUMBER:
      HiveDecimalWritable obj = ( (DecimalColumnVector) columnVector ).vector[ currentBatchRow ];
      return obj.getHiveDecimal().bigDecimalValue();

    case ValueMetaInterface.TYPE_TIMESTAMP:
      Timestamp timestamp = new Timestamp( ( (TimestampColumnVector) columnVector ).time[ currentBatchRow ] );
      timestamp.setNanos( ( (TimestampColumnVector) columnVector ).nanos[ currentBatchRow ] );
      return timestamp;

    case ValueMetaInterface.TYPE_DATE:
      LocalDate localDate =
        LocalDate.ofEpochDay( 0 ).plusDays( ( (LongColumnVector) columnVector ).vector[ currentBatchRow ] );
      Date dateValue = Date.from( localDate.atStartOfDay( ZoneId.systemDefault() ).toInstant() );
      return dateValue;

    case ValueMetaInterface.TYPE_BOOLEAN:
      return ( (LongColumnVector) columnVector ).vector[ currentBatchRow ] == 0 ? false : true;

    case ValueMetaInterface.TYPE_BINARY:
      byte[] origBytes = ( (BytesColumnVector) columnVector ).vector[ currentBatchRow ];
      int startPos = ( (BytesColumnVector) columnVector ).start[ currentBatchRow ];
      byte[] newBytes = Arrays.copyOfRange( origBytes, startPos,
        startPos + ( (BytesColumnVector) columnVector ).length[ currentBatchRow ] );
      return newBytes;
  }

  //if none of the cases match return a null
  return null;
}
 
Example 16
Source File: AccessOutputMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static Object[] createObjectsForRow( RowMetaInterface rowMeta, Object[] rowData ) throws KettleValueException {
  Object[] values = new Object[rowMeta.size()];
  for ( int i = 0; i < rowMeta.size(); i++ ) {
    ValueMetaInterface valueMeta = rowMeta.getValueMeta( i );
    Object valueData = rowData[i];

    // Prevent a NullPointerException below
    if ( valueData == null || valueMeta == null ) {
      values[i] = null;
      continue;
    }

    int length = valueMeta.getLength();

    switch ( valueMeta.getType() ) {
      case ValueMetaInterface.TYPE_INTEGER:
        if ( length < 3 ) {
          values[i] = new Byte( valueMeta.getInteger( valueData ).byteValue() );
        } else {
          if ( length < 5 ) {
            values[i] = new Short( valueMeta.getInteger( valueData ).shortValue() );
          } else {
            values[i] = valueMeta.getInteger( valueData );
          }
        }
        break;
      case ValueMetaInterface.TYPE_NUMBER:
        values[i] = valueMeta.getNumber( valueData );
        break;
      case ValueMetaInterface.TYPE_DATE:
        values[i] = valueMeta.getDate( valueData );
        break;
      case ValueMetaInterface.TYPE_STRING:
        values[i] = valueMeta.getString( valueData );
        break;
      case ValueMetaInterface.TYPE_BINARY:
        values[i] = valueMeta.getBinary( valueData );
        break;
      case ValueMetaInterface.TYPE_BOOLEAN:
        values[i] = valueMeta.getBoolean( valueData );
        break;
      case ValueMetaInterface.TYPE_BIGNUMBER:
        values[i] = valueMeta.getNumber( valueData );
        break;
      default:
        break;
    }
  }
  return values;
}
 
Example 17
Source File: CassandraColumnMetaData.java    From learning-hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Get the Kettle ValueMeta that corresponds to the type of the supplied
 * cassandra column.
 * 
 * @param colName the name of the column to get a ValueMeta for
 * @return the ValueMeta that is appropriate for the type of the supplied
 *         column.
 */
public ValueMetaInterface getValueMetaForColumn(String colName) {
  String type = null;
  // check the key first
  if (colName.equals(getKeyName())) {
    type = m_keyValidator;
  } else {
    type = m_columnMeta.get(colName);
    if (type == null) {
      type = m_defaultValidationClass;
    }
  }

  int kettleType = 0;
  if (type.indexOf("UTF8Type") > 0 || type.indexOf("AsciiType") > 0
      || type.indexOf("UUIDType") > 0 || type.indexOf("CompositeType") > 0) {
    kettleType = ValueMetaInterface.TYPE_STRING;
  } else if (type.indexOf("LongType") > 0 || type.indexOf("IntegerType") > 0
      || type.indexOf("Int32Type") > 0) {
    kettleType = ValueMetaInterface.TYPE_INTEGER;
  } else if (type.indexOf("DoubleType") > 0 || type.indexOf("FloatType") > 0) {
    kettleType = ValueMetaInterface.TYPE_NUMBER;
  } else if (type.indexOf("DateType") > 0) {
    kettleType = ValueMetaInterface.TYPE_DATE;
  } else if (type.indexOf("DecimalType") > 0) {
    kettleType = ValueMetaInterface.TYPE_BIGNUMBER;
  } else if (type.indexOf("BytesType") > 0) {
    kettleType = ValueMetaInterface.TYPE_BINARY;
  } else if (type.indexOf("BooleanType") > 0) {
    kettleType = ValueMetaInterface.TYPE_BOOLEAN;
  }

  ValueMetaInterface newVM = new ValueMeta(colName, kettleType);
  if (m_indexedVals.containsKey(colName)) {
    // make it indexed!
    newVM.setStorageType(ValueMetaInterface.STORAGE_TYPE_INDEXED);
    HashSet<Object> indexedV = m_indexedVals.get(colName);
    Object[] iv = indexedV.toArray();
    newVM.setIndex(iv);
  }

  return newVM;
}
 
Example 18
Source File: SAPDBDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc,
                                  boolean addFieldName, boolean addCr ) {
  String retval = "";

  String fieldname = v.getName();
  int length = v.getLength();
  int precision = v.getPrecision();

  if ( addFieldName ) {
    if ( Const.indexOfString( fieldname, getReservedWords() ) >= 0 ) {
      retval += getStartQuote() + fieldname + getEndQuote();
    } else {
      retval += fieldname + " ";
    }
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
    case ValueMetaInterface.TYPE_DATE:
      retval += "TIMESTAMP";
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      retval += "CHAR(1)";
      break;
    case ValueMetaInterface.TYPE_NUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_BIGNUMBER:
      if ( fieldname.equalsIgnoreCase( tk ) || // Technical key
        fieldname.equalsIgnoreCase( pk ) // Primary key
      ) {
        retval += "BIGINT NOT NULL PRIMARY KEY";
      } else {
        if ( length > 0 ) {
          if ( precision > 0 || length > 18 ) {
            retval += "DECIMAL(" + length;
            if ( precision > 0 ) {
              retval += ", " + precision;
            }
            retval += ")";
          } else {
            if ( length > 9 ) {
              retval += "INT64";
            } else {
              if ( length < 5 ) {
                retval += "SMALLINT";
              } else {
                retval += "INTEGER";
              }
            }
          }

        } else {
          retval += "DOUBLE";
        }
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      if ( length < 32720 ) {
        retval += "VARCHAR";
        if ( length > 0 ) {
          retval += "(" + length + ")";
        } else {
          retval += "(8000)"; // Maybe use some default DB String length?
        }
      } else {
        retval += "BLOB SUB_TYPE TEXT";
      }
      break;
    default:
      retval += " UNKNOWN";
      break;
  }

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

  return retval;
}
 
Example 19
Source File: TeradataDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc,
                                  boolean addFieldName, boolean addCr ) {
  String retval = "";

  String fieldname = v.getName();
  int length = v.getLength();
  int precision = v.getPrecision();

  if ( addFieldName ) {
    retval += fieldname + " ";
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
    case ValueMetaInterface.TYPE_DATE:
      retval += "TIMESTAMP";
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      retval += "CHAR(1)";
      break;
    case ValueMetaInterface.TYPE_NUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_BIGNUMBER:
      if ( fieldname.equalsIgnoreCase( tk ) || // Technical key
        fieldname.equalsIgnoreCase( pk ) // Primary key
      ) {
        retval += "INTEGER"; // TERADATA has no Auto-increment functionality nor Sequences!
      } else {
        if ( length > 0 ) {
          if ( precision > 0 || length > 9 ) {
            retval += "DECIMAL(" + length + ", " + precision + ")";
          } else {
            if ( length > 5 ) {
              retval += "INTEGER";
            } else {
              if ( length < 3 ) {
                retval += "BYTEINT";
              } else {
                retval += "SMALLINT";
              }
            }
          }

        } else {
          retval += "DOUBLE PRECISION";
        }
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      if ( length > 64000 ) {
        retval += "CLOB";
      } else {
        retval += "VARCHAR";
        if ( length > 0 ) {
          retval += "(" + length + ")";
        } else {
          retval += "(64000)"; // Maybe use some default DB String length?
        }
      }
      break;
    default:
      retval += " UNKNOWN";
      break;
  }

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

  return retval;
}
 
Example 20
Source File: TableProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method is called when a row is written to another step (even if there is no next step)
 *
 * @param rowMeta the metadata of the row
 * @param row     the data of the row
 * @throws org.pentaho.di.core.exception.KettleStepException an exception that can be thrown to hard stop the step
 */
public void rowWrittenEvent( final RowMetaInterface rowMeta, final Object[] row ) throws KettleStepException {
  if ( firstCall ) {
    this.tableModel = createTableModel( rowMeta );
    firstCall = false;
  }

  if ( queryLimit > 0 && rowsWritten > queryLimit ) {
    return;
  }

  try {
    rowsWritten += 1;

    final int count = tableModel.getColumnCount();
    final Object dataRow[] = new Object[ count ];
    for ( int columnNo = 0; columnNo < count; columnNo++ ) {
      final ValueMetaInterface valueMeta = rowMeta.getValueMeta( columnNo );

      switch( valueMeta.getType() ) {
        case ValueMetaInterface.TYPE_BIGNUMBER:
          dataRow[ columnNo ] = rowMeta.getBigNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          dataRow[ columnNo ] = rowMeta.getBoolean( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_DATE:
          dataRow[ columnNo ] = rowMeta.getDate( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          dataRow[ columnNo ] = rowMeta.getInteger( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NONE:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          dataRow[ columnNo ] = rowMeta.getNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_STRING:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_BINARY:
          dataRow[ columnNo ] = rowMeta.getBinary( row, columnNo );
          break;
        default:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
      }
    }
    tableModel.addRow( dataRow );
  } catch ( final KettleValueException kve ) {
    throw new KettleStepException( kve );
  } catch ( final Exception e ) {
    throw new KettleStepException( e );
  }
}