Skip to content

Commit 6b806ae

Browse files
committed
Add Python language functions
1 parent 243a82c commit 6b806ae

File tree

11 files changed

+3363
-0
lines changed

11 files changed

+3363
-0
lines changed

plugin/trino-functions-python/pom.xml

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>io.trino</groupId>
6+
<artifactId>trino-root</artifactId>
7+
<version>468-SNAPSHOT</version>
8+
<relativePath>../../pom.xml</relativePath>
9+
</parent>
10+
11+
<artifactId>trino-functions-python</artifactId>
12+
<packaging>trino-plugin</packaging>
13+
<description>Trino - Python language functions</description>
14+
15+
<dependencyManagement>
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.dylibso.chicory</groupId>
19+
<artifactId>bom</artifactId>
20+
<version>1.0.0-M2</version>
21+
<type>pom</type>
22+
<scope>import</scope>
23+
</dependency>
24+
</dependencies>
25+
</dependencyManagement>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>com.dylibso.chicory</groupId>
30+
<artifactId>log</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>com.dylibso.chicory</groupId>
35+
<artifactId>runtime</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>com.dylibso.chicory</groupId>
40+
<artifactId>wasi</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>com.dylibso.chicory</groupId>
45+
<artifactId>wasm</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>com.google.guava</groupId>
50+
<artifactId>guava</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>com.google.jimfs</groupId>
55+
<artifactId>jimfs</artifactId>
56+
<version>1.3.0</version>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>io.airlift</groupId>
61+
<artifactId>log</artifactId>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>io.airlift</groupId>
66+
<artifactId>units</artifactId>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>io.trino</groupId>
71+
<artifactId>trino-plugin-toolkit</artifactId>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>io.trino</groupId>
76+
<artifactId>trino-wasm-python</artifactId>
77+
<version>3.13-1</version>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>joda-time</groupId>
82+
<artifactId>joda-time</artifactId>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>com.fasterxml.jackson.core</groupId>
87+
<artifactId>jackson-annotations</artifactId>
88+
<scope>provided</scope>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>io.airlift</groupId>
93+
<artifactId>slice</artifactId>
94+
<scope>provided</scope>
95+
</dependency>
96+
97+
<dependency>
98+
<groupId>io.opentelemetry</groupId>
99+
<artifactId>opentelemetry-api</artifactId>
100+
<scope>provided</scope>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>io.opentelemetry</groupId>
105+
<artifactId>opentelemetry-context</artifactId>
106+
<scope>provided</scope>
107+
</dependency>
108+
109+
<dependency>
110+
<groupId>io.trino</groupId>
111+
<artifactId>trino-spi</artifactId>
112+
<scope>provided</scope>
113+
</dependency>
114+
115+
<dependency>
116+
<groupId>io.airlift</groupId>
117+
<artifactId>junit-extensions</artifactId>
118+
<scope>test</scope>
119+
</dependency>
120+
121+
<dependency>
122+
<groupId>io.trino</groupId>
123+
<artifactId>trino-main</artifactId>
124+
<scope>test</scope>
125+
</dependency>
126+
127+
<dependency>
128+
<groupId>io.trino</groupId>
129+
<artifactId>trino-main</artifactId>
130+
<type>test-jar</type>
131+
<scope>test</scope>
132+
</dependency>
133+
134+
<dependency>
135+
<groupId>io.trino</groupId>
136+
<artifactId>trino-testing</artifactId>
137+
<scope>test</scope>
138+
</dependency>
139+
140+
<dependency>
141+
<groupId>io.trino</groupId>
142+
<artifactId>trino-tpch</artifactId>
143+
<scope>test</scope>
144+
</dependency>
145+
146+
<dependency>
147+
<groupId>org.assertj</groupId>
148+
<artifactId>assertj-core</artifactId>
149+
<scope>test</scope>
150+
</dependency>
151+
152+
<dependency>
153+
<groupId>org.junit.jupiter</groupId>
154+
<artifactId>junit-jupiter-api</artifactId>
155+
<scope>test</scope>
156+
</dependency>
157+
158+
<dependency>
159+
<groupId>org.junit.jupiter</groupId>
160+
<artifactId>junit-jupiter-engine</artifactId>
161+
<scope>test</scope>
162+
</dependency>
163+
</dependencies>
164+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.plugin.functions.python;
15+
16+
import com.dylibso.chicory.log.Logger;
17+
18+
import static java.util.Objects.requireNonNull;
19+
20+
final class JdkLogger
21+
implements Logger
22+
{
23+
private final java.util.logging.Logger logger;
24+
25+
public static Logger get(Class<?> clazz)
26+
{
27+
return new JdkLogger(java.util.logging.Logger.getLogger(clazz.getName()));
28+
}
29+
30+
public JdkLogger(java.util.logging.Logger logger)
31+
{
32+
this.logger = requireNonNull(logger, "logger is null");
33+
}
34+
35+
@Override
36+
public void log(Level level, String msg, Throwable throwable)
37+
{
38+
logger.log(toJdkLevel(level), msg, throwable);
39+
}
40+
41+
@Override
42+
public boolean isLoggable(Level level)
43+
{
44+
return logger.isLoggable(toJdkLevel(level));
45+
}
46+
47+
private static java.util.logging.Level toJdkLevel(Level level)
48+
{
49+
return switch (level) {
50+
case ALL -> java.util.logging.Level.ALL;
51+
case TRACE -> java.util.logging.Level.FINEST;
52+
case DEBUG -> java.util.logging.Level.FINE;
53+
case INFO -> java.util.logging.Level.INFO;
54+
case WARNING -> java.util.logging.Level.WARNING;
55+
case ERROR -> java.util.logging.Level.SEVERE;
56+
case OFF -> java.util.logging.Level.OFF;
57+
};
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.plugin.functions.python;
15+
16+
import io.airlift.log.Logger;
17+
18+
import java.io.ByteArrayOutputStream;
19+
20+
import static com.google.common.base.CharMatcher.javaIsoControl;
21+
import static java.nio.charset.StandardCharsets.UTF_8;
22+
import static java.util.Objects.requireNonNull;
23+
24+
@SuppressWarnings("UnsynchronizedOverridesSynchronized")
25+
final class LoggingOutputStream
26+
extends ByteArrayOutputStream
27+
{
28+
private final Logger logger;
29+
30+
public LoggingOutputStream(Logger logger)
31+
{
32+
this.logger = requireNonNull(logger, "logger is null");
33+
}
34+
35+
@Override
36+
public void write(byte[] b, int off, int len)
37+
{
38+
if (logger.isDebugEnabled()) {
39+
super.write(b, off, len);
40+
flush();
41+
}
42+
}
43+
44+
@Override
45+
public void flush()
46+
{
47+
if (count > 4096) {
48+
log(toString(UTF_8));
49+
reset();
50+
return;
51+
}
52+
53+
int index;
54+
for (index = count - 1; index >= 0; index--) {
55+
if (buf[index] == '\n') {
56+
break;
57+
}
58+
}
59+
if (index == -1) {
60+
return;
61+
}
62+
63+
String data = new String(buf, 0, index, UTF_8);
64+
data.lines().forEach(this::log);
65+
66+
int remaining = count - index - 1;
67+
System.arraycopy(buf, index + 1, buf, 0, remaining);
68+
count = remaining;
69+
}
70+
71+
@Override
72+
public void close()
73+
{
74+
log(toString(UTF_8));
75+
reset();
76+
}
77+
78+
private void log(String message)
79+
{
80+
String value = javaIsoControl().removeFrom(message).strip();
81+
if (!value.isEmpty()) {
82+
logger.debug(value);
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)