Skip to content

Commit

Permalink
add first by impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Beyyes committed Oct 18, 2024
1 parent 97ad775 commit dbb71d6
Show file tree
Hide file tree
Showing 6 changed files with 623 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1026,12 +1026,28 @@ public void lastByFirstByTest() {

String[] expectedHeader11 = buildHeaders(expectedHeader1.length * 2);
sql =
"select last_by(time,time),last_by(device,time),last_by(level,time),last_by(attr1,time),last_by(attr2,time),last_by(num,time),last_by(bignum,time),last_by(floatnum,time),last_by(str,time),last_by(bool,time),last_by(date,time),last_by(ts,time),last_by(stringv,time),last_by(time,time),last_by(time,device),last_by(time,level),last_by(time,attr1),last_by(time,attr2),last_by(time,num),last_by(time,bignum),last_by(time,floatnum),last_by(time,str),last_by(time,bool),last_by(time,date),last_by(time,ts),last_by(time,stringv) from table0 where device='d2'";
"select last_by(time,time),last_by(device,time),last_by(level,time),last_by(attr1,time),last_by(attr2,time),last_by(num,time),last_by(bignum,time),last_by(floatnum,time),last_by(str,time),last_by(bool,time),last_by(date,time),last_by(ts,time),last_by(stringv,time),last_by(time,time),last_by(time,device),last_by(time,level),last_by(time,attr1),last_by(time,attr2),last_by(time,num),last_by(time,bignum),last_by(time,floatnum),last_by(time,str),last_by(time,bool),last_by(time,date),last_by(time,ts),last_by(time,stringv) from table0 where device='d2'";
retArray =
new String[] {
"1971-08-20T11:33:20.000Z,d2,l5,null,null,15,3147483648,235.213,watermelon,true,2023-01-01,null,null,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-04-26T17:46:40.000Z,1971-01-01T00:01:40.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-01-01T00:01:40.000Z,1971-01-01T00:01:40.000Z,",
};
new String[] {
"1971-08-20T11:33:20.000Z,d2,l5,null,null,15,3147483648,235.213,watermelon,true,2023-01-01,null,null,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-04-26T17:46:40.000Z,1971-01-01T00:01:40.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-08-20T11:33:20.000Z,1971-01-01T00:01:40.000Z,1971-01-01T00:01:40.000Z,",
};
tableResultSetEqualTest(sql, expectedHeader11, retArray, DATABASE_NAME);

sql =
"select first_by(time,time),first_by(device,time),first_by(level,time),first_by(attr1,time),first_by(attr2,time),first_by(num,time),first_by(bignum,time),first_by(floatnum,time),first_by(str,time),first_by(bool,time),first_by(date,time),first_by(ts,time),first_by(stringv,time) from table0 where device='d2' and time>80";
retArray =
new String[] {
"1970-01-01T00:00:00.100Z,d2,l5,null,null,8,2147483964,4654.231,papaya,true,null,null,null,",
};
tableResultSetEqualTest(sql, expectedHeader1, retArray, DATABASE_NAME);

sql =
"select first_by(time,time),first_by(time,device),first_by(time,level),first_by(time,attr1),first_by(time,attr2),first_by(time,num),first_by(time,bignum),first_by(time,floatnum),first_by(time,str),first_by(time,bool),first_by(time,date),first_by(time,ts),first_by(time,stringv) from table0 where device='d2' and time>80";
retArray =
new String[] {
"1970-01-01T00:00:00.100Z,1970-01-01T00:00:00.100Z,1970-01-01T00:00:00.100Z,1971-01-01T00:00:00.000Z,1971-01-01T00:00:00.000Z,1970-01-01T00:00:00.100Z,1970-01-01T00:00:00.100Z,1970-01-01T00:00:00.100Z,1970-01-01T00:00:00.100Z,1970-01-01T00:00:00.100Z,1971-08-20T11:33:20.000Z,1971-01-01T00:01:40.000Z,1971-01-01T00:01:40.000Z,",
};
tableResultSetEqualTest(sql, expectedHeader1, retArray, DATABASE_NAME);
}

// ==================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public class IoTDBConfig {
private long cacheFileReaderClearPeriod = 100000;

/** the max executing time of query in ms. Unit: millisecond */
private long queryTimeoutThreshold = 60000;
private long queryTimeoutThreshold = 60000000;

/** the max time to live of a session in ms. Unit: millisecond */
private int sessionTimeoutThreshold = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ public static TableAccumulator createAccumulator(
} else if ((LAST_BY.getFunctionName().equals(functionName)
|| FIRST_BY.getFunctionName().equals(functionName))
&& inputExpressions.size() > 1) {
boolean xIsTimeColumn = isTimeColumn(inputExpressions.get(0));
boolean yIsTimeColumn = isTimeColumn(inputExpressions.get(1));
boolean xIsTimeColumn = false;
boolean yIsTimeColumn = false;
if (isTimeColumn(inputExpressions.get(1))) {
yIsTimeColumn = true;
} else if (isTimeColumn(inputExpressions.get(0))) {
xIsTimeColumn = true;
}
if (LAST_BY.getFunctionName().equals(functionName)) {
return new LastByAccumulator(
inputDataTypes.get(0), inputDataTypes.get(1), xIsTimeColumn, yIsTimeColumn);
} else {
return new LastByAccumulator(
return new FirstByAccumulator(
inputDataTypes.get(0), inputDataTypes.get(1), xIsTimeColumn, yIsTimeColumn);
}
} else {
Expand Down Expand Up @@ -121,6 +126,8 @@ public static TableAccumulator createBuiltinAccumulator(
return new MinAccumulator(inputDataTypes.get(0));
case LAST_BY:
return new LastByAccumulator(inputDataTypes.get(0), inputDataTypes.get(1), false, false);
case FIRST_BY:
return new FirstByAccumulator(inputDataTypes.get(0), inputDataTypes.get(1), false, false);
default:
throw new IllegalArgumentException("Invalid Aggregation function: " + aggregationType);
}
Expand Down Expand Up @@ -234,37 +241,6 @@ public interface KeepEvaluator {
boolean apply(long keep);
}

// public static KeepEvaluator initKeepEvaluator(Expression keepExpression) {
// // We have checked semantic in FE,
// // keep expression must be ConstantOperand or CompareBinaryExpression here
// if (keepExpression instanceof ConstantOperand) {
// return keep -> keep >= Long.parseLong(keepExpression.getExpressionString());
// } else {
// long constant =
// Long.parseLong(
// ((CompareBinaryExpression) keepExpression)
// .getRightExpression()
// .getExpressionString());
// switch (keepExpression.getExpressionType()) {
// case LESS_THAN:
// return keep -> keep < constant;
// case LESS_EQUAL:
// return keep -> keep <= constant;
// case GREATER_THAN:
// return keep -> keep > constant;
// case GREATER_EQUAL:
// return keep -> keep >= constant;
// case EQUAL_TO:
// return keep -> keep == constant;
// case NON_EQUAL:
// return keep -> keep != constant;
// default:
// throw new IllegalArgumentException(
// "unsupported expression type: " + keepExpression.getExpressionType());
// }
// }
// }

public static boolean isTimeColumn(Expression expression) {
return expression instanceof SymbolReference
&& TIME_COLUMN_NAME.equals(((SymbolReference) expression).getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void evaluateFinal(ColumnBuilder columnBuilder) {

@Override
public boolean hasFinalResult() {
return initResult;
return false;
}

@Override
Expand Down
Loading

0 comments on commit dbb71d6

Please sign in to comment.