-
Notifications
You must be signed in to change notification settings - Fork 445
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
1 parent
310a079
commit 698817d
Showing
9 changed files
with
189 additions
and
34 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
69 changes: 69 additions & 0 deletions
69
...arrow-flight/src/main/java/com/dremio/service/flight/impl/GetCatalogsResponseHandler.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,69 @@ | ||
/* | ||
* Copyright (C) 2017-2019 Dremio Corporation | ||
* | ||
* 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 com.dremio.service.flight.impl; | ||
|
||
import org.apache.arrow.flight.FlightProducer; | ||
import org.apache.arrow.flight.sql.FlightSqlProducer; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
import org.apache.arrow.vector.VarCharVector; | ||
import org.apache.arrow.vector.VectorSchemaRoot; | ||
import org.apache.arrow.vector.util.Text; | ||
|
||
import com.dremio.common.utils.protos.QueryWritableBatch; | ||
import com.dremio.exec.proto.GeneralRPCProtos; | ||
import com.dremio.exec.proto.UserProtos; | ||
import com.dremio.exec.rpc.RpcOutcomeListener; | ||
import com.dremio.exec.work.protector.UserResponseHandler; | ||
import com.dremio.exec.work.protector.UserResult; | ||
|
||
class GetCatalogsResponseHandler implements UserResponseHandler { | ||
private final BufferAllocator allocator; | ||
private final FlightProducer.ServerStreamListener listener; | ||
|
||
public GetCatalogsResponseHandler(BufferAllocator allocator, FlightProducer.ServerStreamListener listener) { | ||
this.allocator = allocator; | ||
this.listener = listener; | ||
} | ||
|
||
@Override | ||
public void sendData(RpcOutcomeListener<GeneralRPCProtos.Ack> outcomeListener, | ||
QueryWritableBatch result) { | ||
} | ||
|
||
@Override | ||
public void completed(UserResult result) { | ||
UserProtos.GetCatalogsResp catalogsResp = result.unwrap(UserProtos.GetCatalogsResp.class); | ||
|
||
try (VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.create(FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA, | ||
allocator)) { | ||
listener.start(vectorSchemaRoot); | ||
|
||
vectorSchemaRoot.allocateNew(); | ||
VarCharVector catalogNameVector = (VarCharVector) vectorSchemaRoot.getVector("catalog_name"); | ||
|
||
int i = 0; | ||
for (UserProtos.CatalogMetadata catalogMetadata : catalogsResp.getCatalogsList()) { | ||
catalogNameVector.setSafe(i, new Text(catalogMetadata.getCatalogName())); | ||
i++; | ||
} | ||
|
||
vectorSchemaRoot.setRowCount(catalogsResp.getCatalogsCount()); | ||
listener.putNext(); | ||
listener.completed(); | ||
} | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...ces/arrow-flight/src/test/java/com/dremio/service/flight/AbstractTestFlightSqlServer.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,59 @@ | ||
/* | ||
* Copyright (C) 2017-2019 Dremio Corporation | ||
* | ||
* 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 com.dremio.service.flight; | ||
|
||
import java.sql.SQLException; | ||
|
||
import org.apache.arrow.flight.CallOption; | ||
import org.apache.arrow.flight.FlightInfo; | ||
import org.apache.arrow.flight.FlightStream; | ||
import org.apache.arrow.flight.sql.FlightSqlClient; | ||
import org.apache.arrow.vector.VarCharVector; | ||
import org.apache.arrow.vector.VectorSchemaRoot; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public abstract class AbstractTestFlightSqlServer extends AbstractTestFlightServer { | ||
|
||
@Override | ||
public FlightInfo getFlightInfo(String query) throws SQLException { | ||
final FlightClientUtils.FlightClientWrapper clientWrapper = getFlightClientWrapper(); | ||
|
||
final FlightSqlClient.PreparedStatement preparedStatement = | ||
clientWrapper.getSqlClient().prepare(query, getCallOptions()); | ||
|
||
return preparedStatement.execute(); | ||
} | ||
|
||
@Test | ||
public void testGetCatalogs() { | ||
FlightSqlClient flightSqlClient = getFlightClientWrapper().getSqlClient(); | ||
CallOption[] callOptions = getCallOptions(); | ||
|
||
FlightInfo flightInfo = flightSqlClient.getCatalogs(callOptions); | ||
try (FlightStream stream = flightSqlClient.getStream(flightInfo.getEndpoints().get(0).getTicket(), callOptions)) { | ||
Assert.assertTrue(stream.next()); | ||
VectorSchemaRoot root = stream.getRoot(); | ||
Assert.assertEquals(1, root.getRowCount()); | ||
|
||
String catalogName = ((VarCharVector) root.getVector("catalog_name")).getObject(0).toString(); | ||
Assert.assertEquals("DREMIO", catalogName); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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