Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-11010] [TABLE] Flink SQL timestamp is inconsistent with currentProcessingTime() #7180

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1449,6 +1449,7 @@ abstract class CodeGenerator(
val resultCode =
s"""
|long $resultTerm = $contextTerm.timerService().currentProcessingTime();
|$resultTerm = $resultTerm + java.util.TimeZone.getDefault().getOffset($resultTerm);
lamberken marked this conversation as resolved.
Show resolved Hide resolved
|""".stripMargin
GeneratedExpression(resultTerm, NEVER_NULL, resultCode, SqlTimeTypeInfo.TIMESTAMP)
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.flink.api.java.typeutils.RowTypeInfo;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.java.StreamTableEnvironment;
Expand All @@ -33,8 +34,10 @@
import org.apache.flink.test.util.AbstractTestBase;
import org.apache.flink.types.Row;

import org.junit.Assert;
import org.junit.Test;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -164,4 +167,35 @@ public void testUnion() throws Exception {

StreamITCase.compareWithList(expected);
}

@Test
public void testProctime() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);

DataStream<Tuple3<Integer, Long, String>> ds = JavaStreamTestData.getSmall3TupleDataSet(env);
tableEnv.registerDataStream("MyTable", ds, "a, b, c, proctime.proctime");

String sqlQuery = "select proctime from MyTable";

Table result = tableEnv.sqlQuery(sqlQuery);

tableEnv
.toAppendStream(result, TypeInformation.of(Row.class))
.addSink(new SinkFunction<Row>() {
@Override
public void invoke(Row value, Context context) throws Exception {

Timestamp procTimestamp = (Timestamp) value.getField(0);

// validate the second here
long procSecondTime = procTimestamp.getTime() / 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes me some trouble because cases can happen when they cross the second boundary. this is not a stable ITCase in my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's better to validate hour. I'll update.

long sysSecondTime = context.currentProcessingTime() / 1000;

Assert.assertTrue(procSecondTime == sysSecondTime);
}
});

env.execute();
}
}