-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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-26474][hive] Fold exprNode to fix the issue of failing to call some hive udf required constant parameters with implicit constant passed #18975
Conversation
00eda42
to
ab66505
Compare
d2abd7a
to
809ed66
Compare
@flinkbot run azure |
fe8db84
to
7ccfaab
Compare
7ccfaab
to
a5d4a7c
Compare
@@ -0,0 +1,13 @@ | |||
-- SORT_QUERY_RESULTS | |||
|
|||
select bround(55.0, -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any test which the second parameter is positive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a query select bround(55.0, +1)
to cover the positive number with +
sign.
For the positive number without +
sign, I think the query select percentile_approx(x, 0.5) from foo
in udaf.q
has covered it.
3241d87
to
c081421
Compare
@flinkbot run azure |
|
The |
@flinkbot run azure |
…quired constant parameters with implicit constant passed.
ba90ddc
to
48ed9d9
Compare
@flinkbot run azure |
@@ -788,7 +788,7 @@ public void testCastTimeStampToDecimal() throws Exception { | |||
timestamp)) | |||
.collect()); | |||
assertThat(results.toString()) | |||
.isEqualTo(String.format("[+I[%s]]", expectTimeStampDecimal.toFormatString(8))); | |||
.isEqualTo(String.format("[+I[%s]]", expectTimeStampDecimal)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason for this change? IIUC, the toFormatString(8)
is on purpose because it is cast to decimal(30,8)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's. But there's a special case when comes to cast constant and constant fold is enabled. Actually, the current behavior is same to Hive.
I try with the following sql in Hive:
hive> select cast(cast('2012-12-19 11:12:19.1234567' as timestamp) as decimal(30,8));
1355915539.1234567
hive> insert into t2 values('2012-12-19 11:12:19.1234567')
hive> select cast(c2 as decimal(30, 8)) from t2;
1355915539.12345670
hive > insert into t1 select * from t2;
hive > select * from t1;
1355915539.12345670
The plan for the sql in hive select cast(cast('2012-12-19 11:12:19.1234567' as timestamp) as decimal(30,8))
is:
STAGE PLANS:
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
TableScan
alias: _dummy_table
Row Limit Per Split: 1
Statistics: Num rows: 1 Data size: 10 Basic stats: COMPLETE Column stats: COMPLETE
Select Operator
expressions: 1355915539.1234567 (type: decimal(30,8))
outputColumnNames: _col0
Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE Column stats: COMPLETE
ListSink
The plan for select cast(c1 as decimal(30, 8)) from t1
is :
STAGE DEPENDENCIES:
Stage-0 is a root stage
STAGE PLANS:
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
TableScan
alias: t1
Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE Column stats: NONE
Select Operator
expressions: CAST( c1 AS decimal(30,8)) (type: decimal(30,8))
outputColumnNames: _col0
Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE Column stats: NONE
ListSink
The reason I found is the HiveDecimalConverter
used to convert data in Hive's GenericUDFToDecimal
function actually won't padding zero for 2012-12-19 11:12:19.1234567
, althogh the type is decimal(30,8)
.
Then, the first sql will select a constant 1355915539.1234567
.
But for the second sql, a further padding will be done which will result 1355915539.12345670
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation.
… some hive udf required constant parameters with implicit constant passed This closes apache#18975
What is the purpose of the change
The change is to enable ExprNode folding and to fold UDFOPNegative.
It's mainly to fix the issue that it'll throw the exception
BROUND second argument only takes constant
when call some hive udf requiring constant parameter with implicit constant like-1
orcast(null as int)
.Brief change log
convertConstant
inHiveParserRexNodeConverter
for the value for the data type ofIntervalYearMonth
/IntervalDayTimeType
will be class ofHiveIntervalYearMonth
,HiveIntervalDayTime
.Verifying this change
Added
udf.q
contains the sql statements that'll fail before this fix.Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: noDocumentation