use of org.knime.core.data.LongValue in project knime-core by knime.
the class LinearInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.LongValue in project knime-core by knime.
the class AverageInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round((prev + next) / 2);
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = (prev + next) / 2;
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.LongValue in project knime-core by knime.
the class LinearInterpolationStatisticMB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(m_colIdx);
if (cell.isMissing()) {
m_numMissing++;
} else {
for (int i = 0; i < m_numMissing; i++) {
DataCell res;
if (m_previous.isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) m_previous).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev);
if (m_previous instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (m_previous instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
m_values.add(res);
}
m_numMissing = 0;
m_previous = cell;
}
}
use of org.knime.core.data.LongValue in project knime-core by knime.
the class BinningUtil method calculateIntegerMaxNoOfBins.
/**
* Calculates the maximum number of bins for the given column spec if it
* is an integer column or returns the given number of bins.
* @param noOfBins the current number of bins
* @param xColSpec to calculate the range for
* @return the maximum number of bins
*/
public static int calculateIntegerMaxNoOfBins(final int noOfBins, final DataColumnSpec xColSpec) {
int result = noOfBins;
if (xColSpec != null && xColSpec.getType().isCompatible(LongValue.class)) {
final DataColumnDomain domain = xColSpec.getDomain();
if (domain != null) {
final LongValue lowerBound = (LongValue) domain.getLowerBound();
final LongValue upperBound = (LongValue) domain.getUpperBound();
double range = (double) upperBound.getLongValue() - (double) lowerBound.getLongValue() + 1.0;
if (range > Integer.MAX_VALUE) {
range = Integer.MAX_VALUE;
}
if (range <= 0) {
// we need at least one bin
range = 1;
}
if (result > range) {
result = (int) range;
}
}
}
return result;
}
use of org.knime.core.data.LongValue in project knime-core by knime.
the class DatabaseHelper method fillStatement.
/**
* Set given column value into SQL statement.
* @param stmt statement used
* @param dbIdx database index to update/write
* @param cspec column spec to check type
* @param cell the data cell to write into the statement
* @param tz the {@link TimeZone} to use
* @param columnTypes
* @throws SQLException if the value can't be set
*/
protected void fillStatement(final PreparedStatement stmt, final int dbIdx, final DataColumnSpec cspec, final DataCell cell, final TimeZone tz, final Map<Integer, Integer> columnTypes) throws SQLException {
if (cspec.getType().isCompatible(BooleanValue.class)) {
if (cell.isMissing()) {
stmt.setNull(dbIdx, Types.BOOLEAN);
} else {
boolean bool = ((BooleanValue) cell).getBooleanValue();
stmt.setBoolean(dbIdx, bool);
}
} else if (cspec.getType().isCompatible(IntValue.class)) {
if (cell.isMissing()) {
stmt.setNull(dbIdx, Types.INTEGER);
} else {
int integer = ((IntValue) cell).getIntValue();
stmt.setInt(dbIdx, integer);
}
} else if (cspec.getType().isCompatible(LongValue.class)) {
if (cell.isMissing()) {
stmt.setNull(dbIdx, Types.BIGINT);
} else {
long dbl = ((LongValue) cell).getLongValue();
stmt.setLong(dbIdx, dbl);
}
} else if (cspec.getType().isCompatible(DoubleValue.class)) {
if (cell.isMissing()) {
stmt.setNull(dbIdx, Types.DOUBLE);
} else {
double dbl = ((DoubleValue) cell).getDoubleValue();
if (Double.isNaN(dbl)) {
stmt.setNull(dbIdx, Types.DOUBLE);
} else {
stmt.setDouble(dbIdx, dbl);
}
}
} else if (cspec.getType().isCompatible(DateAndTimeValue.class)) {
if (cell.isMissing()) {
stmt.setNull(dbIdx, Types.DATE);
} else {
final DateAndTimeValue dateCell = (DateAndTimeValue) cell;
final long corrDate = dateCell.getUTCTimeInMillis() - tz.getOffset(dateCell.getUTCTimeInMillis());
if (!dateCell.hasTime() && !dateCell.hasMillis()) {
java.sql.Date date = new java.sql.Date(corrDate);
stmt.setDate(dbIdx, date);
} else if (!dateCell.hasDate()) {
java.sql.Time time = new java.sql.Time(corrDate);
stmt.setTime(dbIdx, time);
} else {
java.sql.Timestamp timestamp = new java.sql.Timestamp(corrDate);
stmt.setTimestamp(dbIdx, timestamp);
}
}
} else if (cspec.getType().isCompatible(BinaryObjectDataValue.class)) {
if (cell.isMissing()) {
stmt.setNull(dbIdx, Types.BLOB);
} else {
try {
BinaryObjectDataValue value = (BinaryObjectDataValue) cell;
InputStream is = value.openInputStream();
if (is == null) {
stmt.setNull(dbIdx, Types.BLOB);
} else {
try {
// to be compatible with JDBC 3.0, the length of the stream is restricted to max integer,
// which are ~2GB; with JDBC 4.0 longs are supported and the respective method can be called
stmt.setBinaryStream(dbIdx, is, (int) value.length());
} catch (SQLException ex) {
// if no supported (i.e. SQLite) set byte array
byte[] bytes = IOUtils.toByteArray(is);
stmt.setBytes(dbIdx, bytes);
}
}
} catch (IOException ioe) {
stmt.setNull(dbIdx, Types.BLOB);
}
}
} else if (cspec.getType().isCompatible(CollectionDataValue.class)) {
fillArray(stmt, dbIdx, cell, tz);
} else if ((columnTypes == null) || cspec.getType().isCompatible(StringValue.class)) {
if (cell.isMissing()) {
stmt.setNull(dbIdx, Types.VARCHAR);
} else {
stmt.setString(dbIdx, cell.toString());
}
} else {
Integer sqlType = columnTypes.get(dbIdx);
if (sqlType == null) {
sqlType = Types.VARCHAR;
}
if (cell.isMissing()) {
stmt.setNull(dbIdx, sqlType);
} else {
stmt.setObject(dbIdx, cell.toString(), sqlType);
}
}
}
Aggregations