forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 3
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
6 changed files
with
154 additions
and
122 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
80 changes: 0 additions & 80 deletions
80
fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/FlightSqlChannel.java
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/results/FlightSqlChannel.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,120 @@ | ||
// 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.doris.service.arrowflight.results; | ||
|
||
import org.apache.doris.catalog.Column; | ||
import org.apache.doris.common.FeConstants; | ||
import org.apache.doris.qe.ResultSet; | ||
import org.apache.doris.qe.ResultSetMetaData; | ||
|
||
import com.google.common.cache.Cache; | ||
import com.google.common.cache.CacheBuilder; | ||
import com.google.common.cache.RemovalListener; | ||
import com.google.common.cache.RemovalNotification; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.arrow.util.AutoCloseables; | ||
import org.apache.arrow.vector.FieldVector; | ||
import org.apache.arrow.vector.VarCharVector; | ||
import org.apache.arrow.vector.VectorSchemaRoot; | ||
import org.apache.arrow.vector.types.pojo.ArrowType.Utf8; | ||
import org.apache.arrow.vector.types.pojo.Field; | ||
import org.apache.arrow.vector.types.pojo.FieldType; | ||
import org.apache.arrow.vector.types.pojo.Schema; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class FlightSqlChannel { | ||
private final Cache<String, FlightSqlResultCacheEntry> resultCache; | ||
private final BufferAllocator allocator; | ||
|
||
public FlightSqlChannel() { | ||
resultCache = | ||
CacheBuilder.newBuilder() | ||
.maximumSize(100) | ||
.expireAfterWrite(10, TimeUnit.MINUTES) | ||
.removalListener(new ResultRemovalListener()) | ||
.build(); | ||
allocator = new RootAllocator(Long.MAX_VALUE); | ||
} | ||
|
||
// TODO | ||
public String getRemoteIp() { | ||
return "0.0.0.0"; | ||
} | ||
|
||
// TODO | ||
public String getRemoteHostPortString() { | ||
return "0.0.0.0:0"; | ||
} | ||
|
||
public void addResultSet(String queryId, String runningQuery, ResultSet resultSet) { | ||
List<Field> schemaFields = new ArrayList<>(); | ||
List<FieldVector> dataFields = new ArrayList<>(); | ||
List<List<String>> resultData = resultSet.getResultRows(); | ||
ResultSetMetaData metaData = resultSet.getMetaData(); | ||
|
||
// TODO: only support varchar type | ||
for (Column col : metaData.getColumns()) { | ||
schemaFields.add(new Field(col.getName(), FieldType.nullable(new Utf8()), null)); | ||
VarCharVector varCharVector = new VarCharVector(col.getName(), allocator); | ||
varCharVector.allocateNew(); | ||
varCharVector.setValueCount(resultData.size()); | ||
dataFields.add(varCharVector); | ||
} | ||
Schema schema = new Schema(schemaFields); | ||
|
||
for (int i = 0; i < resultData.size(); i++) { | ||
List<String> row = resultData.get(i); | ||
for (int j = 0; j < row.size(); j++) { | ||
String item = row.get(j); | ||
if (item == null || item.equals(FeConstants.null_string)) { | ||
dataFields.get(j).setNull(i); | ||
} else { | ||
((VarCharVector) dataFields.get(j)).setSafe(i, item.getBytes()); | ||
} | ||
} | ||
} | ||
VectorSchemaRoot vectorSchemaRoot = new VectorSchemaRoot(schemaFields, dataFields); | ||
final FlightSqlResultCacheEntry flightSqlResultCacheEntry = new FlightSqlResultCacheEntry(vectorSchemaRoot, | ||
runningQuery); | ||
resultCache.put(queryId, flightSqlResultCacheEntry); | ||
} | ||
|
||
public FlightSqlResultCacheEntry getResultSet(String queryId) { | ||
return resultCache.getIfPresent(queryId); | ||
} | ||
|
||
public void invalidate(String handle) { | ||
resultCache.invalidate(handle); | ||
} | ||
|
||
private static class ResultRemovalListener implements RemovalListener<String, FlightSqlResultCacheEntry> { | ||
@Override | ||
public void onRemoval(@NotNull final RemovalNotification<String, FlightSqlResultCacheEntry> notification) { | ||
try { | ||
AutoCloseables.close(notification.getValue()); | ||
} catch (final Exception e) { | ||
// swallow | ||
} | ||
} | ||
} | ||
} |
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