Created
February 9, 2025 12:45
-
-
Save wendigo/6db4b16c627ccf560a0e3d692d1ed2a6 to your computer and use it in GitHub Desktop.
List all segments
This file contains hidden or 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
/* | |
* Licensed 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 io.trino.testing; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import io.airlift.json.ObjectMapperProvider; | |
import io.trino.client.ClientSession; | |
import io.trino.client.QueryData; | |
import io.trino.client.StatementClient; | |
import io.trino.client.TrinoJsonCodec; | |
import io.trino.client.spooling.EncodedQueryData; | |
import io.trino.server.protocol.spooling.QueryDataJacksonModule; | |
import okhttp3.OkHttpClient; | |
import java.io.IOException; | |
import java.net.URI; | |
import java.util.Map; | |
import java.util.Optional; | |
import static io.trino.client.StatementClientFactory.newStatementClient; | |
import static io.trino.client.TrinoJsonCodec.jsonCodec; | |
import static java.time.ZoneId.systemDefault; | |
public class TestClient | |
{ | |
private TestClient() {} | |
public static void main(String[] args) | |
throws InterruptedException, IOException | |
{ | |
TrinoJsonCodec<QueryData> clientCodec = jsonCodec(QueryData.class); | |
ObjectMapper serverMapper = new ObjectMapperProvider().get().registerModule(new QueryDataJacksonModule()); | |
OkHttpClient okHttpClient = new OkHttpClient(); | |
ClientSession session = ClientSession.builder() | |
.server(URI.create("http://localhost:8080")) | |
.user(Optional.of("admin")) | |
.source("wendigo/v1.1") | |
.timeZone(systemDefault()) | |
.encoding(Optional.of("json")) | |
.properties(Map.of("spooling_inlining_enabled", "false")) | |
.build(); | |
try (StatementClient clientV1 = newStatementClient(okHttpClient, okHttpClient, session, "select comment from tpch.sf10.lineitem limit 5_000_000", Optional.empty())) { | |
while (clientV1.advance()) { | |
if (clientV1.currentData() instanceof EncodedQueryData) { | |
String serialized = serverMapper.writeValueAsString(clientV1.currentData()); | |
QueryData deserialized = clientCodec.fromJson(serialized); | |
System.out.println("Serialized is " + serialized); | |
System.out.println("deserialized is " + deserialized); | |
} | |
} | |
} | |
okHttpClient.dispatcher().executorService().shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment