public static List<Tuple> constructSamplePeopleTuples() { IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateTimeField(LocalDateTime.parse("1970-01-01T11:11:11")), new TextField("banana") }; IField[] fields2 = { new StringField("tom hanks"), new StringField("cruise"), new IntegerField(45), new DoubleField(5.95), new DateTimeField(LocalDateTime.parse("1980-01-02T13:14:15")), new TextField("mississippi") }; Tuple tuple1 = new Tuple(SCHEMA_PEOPLE, fields1); Tuple tuple2 = new Tuple(SCHEMA_PEOPLE, fields2); return Arrays.asList(tuple1, tuple2); } }
private boolean compareDateTime(Tuple inputTuple) throws DataflowException { LocalDateTime dateTime = inputTuple.getField(predicate.getAttributeName(), DateTimeField.class).getValue(); String compareToString = predicate.getCompareToValue().toString(); // try to parse the input as date time string first try { LocalDateTime compareToDateTime = LocalDateTime.parse(compareToString); return compareValues(dateTime, compareToDateTime, predicate.getComparisonType()); } catch (DateTimeParseException e) { // if it fails, then try to parse as date time string and compare on date try { LocalDate compareToDate = LocalDate.parse(compareToString); return compareValues(dateTime.toLocalDate(), compareToDate, predicate.getComparisonType()); } catch ( DateTimeParseException e2) { throw new DataflowException("Unable to parse date or time: " + compareToString); } } }
break; case DATETIME: field = new DateTimeField(fieldValue); break; case TEXT:
private int compare(IField a, IField b, AttributeType attrType) { int retVal = 0; switch (attrType) { case INTEGER: retVal = ((IntegerField) a).getValue().compareTo(((IntegerField) b).getValue()); break; case DOUBLE: retVal = ((DoubleField) a).getValue().compareTo(((DoubleField) b).getValue()); break; case TEXT: retVal = ((TextField) a).getValue().compareTo(((TextField) b).getValue()); break; case STRING: retVal = ((StringField) a).getValue().compareTo(((StringField) b).getValue()); break; case DATE: retVal = ((DateField) a).getValue().compareTo(((DateField) b).getValue()); break; case DATETIME: retVal = ((DateTimeField) a).getValue().compareTo(((DateTimeField) b).getValue()); break; } return retVal; }