-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
194 additions
and
20 deletions.
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
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
111 changes: 111 additions & 0 deletions
111
...n/trino-pinot/src/main/java/io/trino/plugin/pinot/query/PinotProxyGrpcRequestBuilder.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,111 @@ | ||
/* | ||
* 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.plugin.pinot.query; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.pinot.common.proto.Server; | ||
import org.apache.pinot.spi.utils.CommonConstants; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class PinotProxyGrpcRequestBuilder | ||
{ | ||
private static final String KEY_OF_PROXY_GRPC_FORWARD_HOST = "FORWARD_HOST"; | ||
private static final String KEY_OF_PROXY_GRPC_FORWARD_PORT = "FORWARD_PORT"; | ||
|
||
private String hostName; | ||
private int port = -1; | ||
private int requestId; | ||
private String brokerId = "unknown"; | ||
private boolean enableTrace; | ||
private boolean enableStreaming; | ||
private String payloadType; | ||
private String sql; | ||
private List<String> segments; | ||
|
||
public PinotProxyGrpcRequestBuilder setHostName(String hostName) | ||
{ | ||
this.hostName = hostName; | ||
return this; | ||
} | ||
|
||
public PinotProxyGrpcRequestBuilder setPort(int port) | ||
{ | ||
this.port = port; | ||
return this; | ||
} | ||
|
||
public PinotProxyGrpcRequestBuilder setRequestId(int requestId) | ||
{ | ||
this.requestId = requestId; | ||
return this; | ||
} | ||
|
||
public PinotProxyGrpcRequestBuilder setBrokerId(String brokerId) | ||
{ | ||
this.brokerId = brokerId; | ||
return this; | ||
} | ||
|
||
public PinotProxyGrpcRequestBuilder setEnableTrace(boolean enableTrace) | ||
{ | ||
this.enableTrace = enableTrace; | ||
return this; | ||
} | ||
|
||
public PinotProxyGrpcRequestBuilder setEnableStreaming(boolean enableStreaming) | ||
{ | ||
this.enableStreaming = enableStreaming; | ||
return this; | ||
} | ||
|
||
public PinotProxyGrpcRequestBuilder setSql(String sql) | ||
{ | ||
payloadType = CommonConstants.Query.Request.PayloadType.SQL; | ||
this.sql = sql; | ||
return this; | ||
} | ||
|
||
public PinotProxyGrpcRequestBuilder setSegments(List<String> segments) | ||
{ | ||
this.segments = ImmutableList.copyOf(segments); | ||
return this; | ||
} | ||
|
||
public Server.ServerRequest build() | ||
{ | ||
if (!payloadType.equals(CommonConstants.Query.Request.PayloadType.SQL)) { | ||
throw new RuntimeException("Only [SQL] Payload type is allowed: " + payloadType); | ||
} | ||
Map<String, String> metadata = new HashMap<>(); | ||
metadata.put(CommonConstants.Query.Request.MetadataKeys.REQUEST_ID, Integer.toString(requestId)); | ||
metadata.put(CommonConstants.Query.Request.MetadataKeys.BROKER_ID, brokerId); | ||
metadata.put(CommonConstants.Query.Request.MetadataKeys.ENABLE_TRACE, Boolean.toString(enableTrace)); | ||
metadata.put(CommonConstants.Query.Request.MetadataKeys.ENABLE_STREAMING, Boolean.toString(enableStreaming)); | ||
metadata.put(CommonConstants.Query.Request.MetadataKeys.PAYLOAD_TYPE, payloadType); | ||
if (this.hostName != null) { | ||
metadata.put(KEY_OF_PROXY_GRPC_FORWARD_HOST, this.hostName); | ||
} | ||
if (this.port > 0) { | ||
metadata.put(KEY_OF_PROXY_GRPC_FORWARD_PORT, String.valueOf(this.port)); | ||
} | ||
return Server.ServerRequest.newBuilder() | ||
.putAllMetadata(metadata) | ||
.setSql(sql) | ||
.addAllSegments(segments) | ||
.build(); | ||
} | ||
} |
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