-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Feature][Zeta] add from_unixtime function #5462
Merged
EricJoy2048
merged 11 commits into
apache:dev
from
chovy-3012:feature/from_unixtime_function
Nov 20, 2023
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
673ca4f
[feature] add from_unixtime function
91048be
[doc] update release-node
a9d9aa0
[test] add from_unixtime function unit test
db15a73
[doc][feature] add doc about this function, add timezone arg in from_…
6914112
[doc] apply codee style on sql-functions.md
46c649d
[test] modify unit test
0968572
Merge branch 'dev' into feature/from_unixtime_function
chovy-3012 e2c0f3c
[test] add e2e test case
7da79df
modify e2e ut
chovy-3012 ac28d20
modify e2e ut
chovy-3012 25d1b73
Merge branch 'apache:dev' into feature/from_unixtime_function
chovy-3012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...atunnel-transforms-v2-e2e-part-2/src/test/resources/sql_transform/func_from_unixtime.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
###### | ||
###### This config file is a demonstration of streaming processing in seatunnel config | ||
###### | ||
|
||
env { | ||
execution.parallelism = 1 | ||
job.mode = "BATCH" | ||
checkpoint.interval = 10000 | ||
} | ||
|
||
source { | ||
FakeSource { | ||
result_table_name = "fake" | ||
schema = { | ||
fields { | ||
unixtime = "bigint" | ||
} | ||
} | ||
rows = [ | ||
{fields = [1672502400], kind = INSERT} | ||
] | ||
} | ||
} | ||
|
||
transform { | ||
Sql { | ||
source_table_name = "fake" | ||
result_table_name = "fake1" | ||
query = "select from_unixtime(unixtime,'yyyy-MM-dd HH:mm:ss','UTC+8') as ts from fake" | ||
} | ||
} | ||
|
||
sink { | ||
Console { | ||
source_table_name = "fake1" | ||
} | ||
Assert { | ||
source_table_name = "fake1" | ||
rules = { | ||
field_rules = [ | ||
{ | ||
field_name = "ts" | ||
field_type = "string" | ||
field_value = [ | ||
{equals_to = "2023-01-01 00:00:00"} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...sforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/DateTimeFunctionTest.java
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes , I've already added unit test for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.transform.sql.zeta; | ||
|
||
import org.apache.seatunnel.api.table.type.BasicType; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelDataType; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelRow; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelRowType; | ||
import org.apache.seatunnel.transform.sql.SQLEngine; | ||
import org.apache.seatunnel.transform.sql.SQLEngineFactory; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class DateTimeFunctionTest { | ||
|
||
@Test | ||
public void testFromUnixtimeFunction() { | ||
|
||
SQLEngine sqlEngine = SQLEngineFactory.getSQLEngine(SQLEngineFactory.EngineType.ZETA); | ||
|
||
SeaTunnelRowType rowType = | ||
new SeaTunnelRowType( | ||
new String[] {"unixtime"}, new SeaTunnelDataType[] {BasicType.LONG_TYPE}); | ||
|
||
// 1672502400 means `2023-01-01 12:00:00 UTC+8` in unix time | ||
Long unixTime = 1672545600L; | ||
SeaTunnelRow inputRow = new SeaTunnelRow(new Long[] {unixTime}); | ||
|
||
// transform by `from_unixtime` function | ||
sqlEngine.init( | ||
"test", | ||
null, | ||
rowType, | ||
"select from_unixtime(unixtime,'yyyy-MM-dd') as ts from test"); | ||
SeaTunnelRow outRow = sqlEngine.transformBySQL(inputRow); | ||
Object field = outRow.getField(0); | ||
Assertions.assertNotNull(field.toString()); | ||
|
||
// transform by `from_unixtime` time zone function | ||
sqlEngine.init( | ||
"test", | ||
null, | ||
rowType, | ||
"select from_unixtime(unixtime,'yyyy-MM-dd HH:mm:ss','UTC+6') as ts from test"); | ||
SeaTunnelRow outRow1 = sqlEngine.transformBySQL(inputRow); | ||
Object field1 = outRow1.getField(0); | ||
Assertions.assertEquals("2023-01-01 10:00:00", field1.toString()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
conflict resolved