Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/trino-functions-python/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-wasm-python</artifactId>
<version>3.13-3</version>
<version>3.13-4</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.dylibso.chicory.wasi.WasiPreview1;
import com.dylibso.chicory.wasm.ChicoryException;
import com.dylibso.chicory.wasm.WasmModule;
import com.dylibso.chicory.wasm.types.FunctionType;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Closer;
import com.google.common.jimfs.Configuration;
Expand All @@ -36,7 +37,8 @@
import io.trino.spi.StandardErrorCode;
import io.trino.spi.TrinoException;
import io.trino.spi.type.Type;
import io.trino.wasm.python.PythonModule;
import io.trino.wasm.python.Python;
import io.trino.wasm.python.PythonMachine;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
Expand All @@ -50,7 +52,7 @@
import java.util.Map;
import java.util.stream.Stream;

import static com.dylibso.chicory.wasm.types.ValueType.I32;
import static com.dylibso.chicory.wasm.types.ValType.I32;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.airlift.units.DataSize.Unit.MEGABYTE;
import static io.trino.plugin.functions.python.TrinoTypes.binaryToJava;
Expand Down Expand Up @@ -78,7 +80,7 @@ final class PythonEngine
private static final Map<Integer, ErrorCodeSupplier> ERROR_CODES = Stream.of(StandardErrorCode.values())
.collect(toImmutableMap(error -> error.toErrorCode().getCode(), identity()));

private static final WasmModule PYTHON_MODULE = PythonModule.load();
private static final WasmModule PYTHON_MODULE = Python.load();

private final Closer closer = Closer.create();
private final LimitedOutputStream stderr = new LimitedOutputStream();
Expand Down Expand Up @@ -123,7 +125,7 @@ public PythonEngine(String guestCode)
.build();

Instance instance = Instance.builder(PYTHON_MODULE)
.withMachineFactory(PythonModule::create)
.withMachineFactory(PythonMachine::new)
.withImportValues(importValues)
.build();

Expand Down Expand Up @@ -276,8 +278,7 @@ private HostFunction returnErrorHostFunction()
return new HostFunction(
"trino",
"return_error",
List.of(I32, I32, I32, I32, I32),
List.of(),
FunctionType.of(List.of(I32, I32, I32, I32, I32), List.of()),
this::returnError);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ SELECT my_func(nationkey)
.matches("VALUES bigint '42'");
}

@Test
public void testImportingAndRunningBleach()
{
assertThat(assertions.query(
"""
WITH FUNCTION sanitize_html(html_input VARCHAR)
RETURNS VARCHAR
LANGUAGE PYTHON
WITH (handler = 'sanitize_html')
AS $$
import bleach
def sanitize_html(html_input):
return bleach.clean(html_input, tags={'b'}, attributes={}, strip=True)
$$
SELECT sanitize_html('<b><i>an example</i></b>')
"""))
.matches("VALUES varchar '<b>an example</b>'");
}

@Test
public void testInvalidHandler()
{
Expand Down