-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Zeta] add from_unixtime function (#5462)
- Loading branch information
1 parent
69f79af
commit fb24f8e
Showing
8 changed files
with
183 additions
and
1 deletion.
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
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()); | ||
} | ||
} |