forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Java support #14
Merged
kou
merged 1 commit into
kou:flight-long-running-queries
from
lidavidm:flight-long-running-queries
Jul 31, 2023
Merged
Add Java support #14
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,22 @@ void listFlights(CallContext context, Criteria criteria, | |
*/ | ||
FlightInfo getFlightInfo(CallContext context, FlightDescriptor descriptor); | ||
|
||
/** | ||
* Begin or get an update on execution of a long-running query. | ||
* | ||
* <p>If the descriptor would begin a query, the server should return a response immediately to not | ||
* block the client. Otherwise, the server should not return an update until progress is made to | ||
* not spam the client with inactionable updates. | ||
* | ||
* @param context Per-call context. | ||
* @param descriptor The descriptor identifying the data stream. | ||
* @return Metadata about execution. | ||
*/ | ||
default RetryInfo pollFlightInfo(CallContext context, FlightDescriptor descriptor) { | ||
FlightInfo info = getFlightInfo(context, descriptor); | ||
return new RetryInfo(info, null, null, null); | ||
} | ||
Comment on lines
+66
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, we can use |
||
|
||
/** | ||
* Get schema for a particular data stream. | ||
* | ||
|
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
160 changes: 160 additions & 0 deletions
160
java/flight/flight-core/src/main/java/org/apache/arrow/flight/RetryInfo.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,160 @@ | ||
/* | ||
* 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.arrow.flight; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.ByteBuffer; | ||
import java.time.Instant; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.apache.arrow.flight.impl.Flight; | ||
|
||
import com.google.protobuf.Timestamp; | ||
|
||
/** | ||
* A POJO representation of the execution of a long-running query. | ||
*/ | ||
public class RetryInfo { | ||
private final FlightInfo flightInfo; | ||
private final FlightDescriptor flightDescriptor; | ||
private final Double progress; | ||
private final Instant expirationTime; | ||
|
||
/** | ||
* Create a new RetryInfo. | ||
* | ||
* @param flightInfo The FlightInfo (must not be null). | ||
* @param flightDescriptor The descriptor used to poll for more information; null if and only if query is finished. | ||
* @param progress Optional progress info in [0.0, 1.0]. | ||
* @param expirationTime An expiration time, after which the server may no longer recognize the descriptor. | ||
*/ | ||
public RetryInfo(FlightInfo flightInfo, FlightDescriptor flightDescriptor, Double progress, Instant expirationTime) { | ||
this.flightInfo = Objects.requireNonNull(flightInfo); | ||
this.flightDescriptor = flightDescriptor; | ||
this.progress = progress; | ||
this.expirationTime = expirationTime; | ||
} | ||
|
||
RetryInfo(Flight.RetryInfo flt) throws URISyntaxException { | ||
this.flightInfo = new FlightInfo(flt.getInfo()); | ||
this.flightDescriptor = flt.hasFlightDescriptor() ? new FlightDescriptor(flt.getFlightDescriptor()) : null; | ||
this.progress = flt.hasProgress() ? flt.getProgress() : null; | ||
this.expirationTime = flt.hasExpirationTime() ? | ||
Instant.ofEpochSecond(flt.getExpirationTime().getSeconds(), flt.getExpirationTime().getNanos()) : | ||
null; | ||
} | ||
|
||
/** | ||
* The FlightInfo describing the result set of the execution of a query. | ||
* | ||
* <p>This is always present and always contains all endpoints for the query execution so far, | ||
* not just new endpoints that completed execution since the last call to | ||
* {@link FlightClient#pollInfo(FlightDescriptor, CallOption...)}. | ||
*/ | ||
public FlightInfo getFlightInfo() { | ||
return flightInfo; | ||
} | ||
|
||
/** | ||
* The FlightDescriptor that should be used to get further updates on this query. | ||
* | ||
* <p>It is present if and only if the query is still running. If present, it should be passed to | ||
* {@link FlightClient#pollInfo(FlightDescriptor, CallOption...)} to get an update. | ||
*/ | ||
public Optional<FlightDescriptor> getFlightDescriptor() { | ||
return Optional.ofNullable(flightDescriptor); | ||
} | ||
|
||
/** | ||
* The progress of the query. | ||
* | ||
* <p>If present, should be a value in [0.0, 1.0]. It is not necessarily monotonic or non-decreasing. | ||
*/ | ||
public Optional<Double> getProgress() { | ||
return Optional.ofNullable(progress); | ||
} | ||
|
||
/** | ||
* The expiration time of the query execution. | ||
* | ||
* <p>After this passes, the server may not recognize the descriptor anymore and the client will not | ||
* be able to track the query anymore. | ||
*/ | ||
public Optional<Instant> getExpirationTime() { | ||
return Optional.ofNullable(expirationTime); | ||
} | ||
|
||
Flight.RetryInfo toProtocol() { | ||
Flight.RetryInfo.Builder b = Flight.RetryInfo.newBuilder(); | ||
b.setInfo(flightInfo.toProtocol()); | ||
if (flightDescriptor != null) { | ||
b.setFlightDescriptor(flightDescriptor.toProtocol()); | ||
} | ||
if (progress != null) { | ||
b.setProgress(progress); | ||
} | ||
if (expirationTime != null) { | ||
b.setExpirationTime( | ||
Timestamp.newBuilder() | ||
.setSeconds(expirationTime.getEpochSecond()) | ||
.setNanos(expirationTime.getNano()) | ||
.build()); | ||
} | ||
return b.build(); | ||
} | ||
|
||
public ByteBuffer serialize() { | ||
return ByteBuffer.wrap(toProtocol().toByteArray()); | ||
} | ||
|
||
public static RetryInfo deserialize(ByteBuffer serialized) throws IOException, URISyntaxException { | ||
return new RetryInfo(Flight.RetryInfo.parseFrom(serialized)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
RetryInfo retryInfo = (RetryInfo) o; | ||
return Objects.equals(getFlightInfo(), retryInfo.getFlightInfo()) && | ||
Objects.equals(getFlightDescriptor(), retryInfo.getFlightDescriptor()) && | ||
Objects.equals(getProgress(), retryInfo.getProgress()) && | ||
Objects.equals(getExpirationTime(), retryInfo.getExpirationTime()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getFlightInfo(), getFlightDescriptor(), getProgress(), getExpirationTime()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RetryInfo{" + | ||
"flightInfo=" + flightInfo + | ||
", flightDescriptor=" + flightDescriptor + | ||
", progress=" + progress + | ||
", expirationTime=" + expirationTime + | ||
'}'; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoProducer.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,56 @@ | ||
/* | ||
* 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.arrow.flight.integration.tests; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.apache.arrow.flight.FlightDescriptor; | ||
import org.apache.arrow.flight.FlightEndpoint; | ||
import org.apache.arrow.flight.FlightInfo; | ||
import org.apache.arrow.flight.NoOpFlightProducer; | ||
import org.apache.arrow.flight.RetryInfo; | ||
import org.apache.arrow.flight.Ticket; | ||
import org.apache.arrow.vector.types.Types; | ||
import org.apache.arrow.vector.types.pojo.Field; | ||
import org.apache.arrow.vector.types.pojo.Schema; | ||
|
||
/** Test PollFlightInfo. */ | ||
class PollFlightInfoProducer extends NoOpFlightProducer { | ||
static final byte[] RETRY_DESCRIPTOR = "retry".getBytes(StandardCharsets.UTF_8); | ||
|
||
@Override | ||
public RetryInfo pollFlightInfo(CallContext context, FlightDescriptor descriptor) { | ||
Schema schema = new Schema( | ||
Collections.singletonList(Field.notNullable("number", Types.MinorType.UINT4.getType()))); | ||
List<FlightEndpoint> endpoints = Collections.singletonList( | ||
new FlightEndpoint( | ||
new Ticket("long-running query".getBytes(StandardCharsets.UTF_8)))); | ||
FlightInfo info = new FlightInfo(schema, descriptor, endpoints, -1, -1 ); | ||
if (descriptor.isCommand() && Arrays.equals(descriptor.getCommand(), RETRY_DESCRIPTOR)) { | ||
return new RetryInfo(info, null, 1.0, null); | ||
} else { | ||
return new RetryInfo( | ||
info, FlightDescriptor.command(RETRY_DESCRIPTOR), 0.1, Instant.now().plus(10, ChronoUnit.SECONDS)); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoScenario.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,62 @@ | ||
/* | ||
* 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.arrow.flight.integration.tests; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Optional; | ||
|
||
import org.apache.arrow.flight.FlightClient; | ||
import org.apache.arrow.flight.FlightDescriptor; | ||
import org.apache.arrow.flight.FlightProducer; | ||
import org.apache.arrow.flight.FlightServer; | ||
import org.apache.arrow.flight.Location; | ||
import org.apache.arrow.flight.RetryInfo; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
|
||
/** Test PollFlightInfo. */ | ||
final class PollFlightInfoScenario implements Scenario { | ||
@Override | ||
public FlightProducer producer(BufferAllocator allocator, Location location) throws Exception { | ||
return new PollFlightInfoProducer(); | ||
} | ||
|
||
@Override | ||
public void buildServer(FlightServer.Builder builder) throws Exception { | ||
} | ||
|
||
@Override | ||
public void client(BufferAllocator allocator, Location location, FlightClient client) throws Exception { | ||
RetryInfo info = client.pollInfo(FlightDescriptor.command("heavy query".getBytes(StandardCharsets.UTF_8))); | ||
IntegrationAssertions.assertNotNull(info.getFlightInfo()); | ||
Optional<Double> progress = info.getProgress(); | ||
IntegrationAssertions.assertTrue("progress is missing", progress.isPresent()); | ||
IntegrationAssertions.assertTrue("progress is invalid", progress.get() >= 0.0 && progress.get() <= 1.0); | ||
IntegrationAssertions.assertTrue("expiration is missing", info.getExpirationTime().isPresent()); | ||
IntegrationAssertions.assertTrue("descriptor is missing", | ||
info.getFlightDescriptor().isPresent()); | ||
|
||
info = client.pollInfo(info.getFlightDescriptor().get()); | ||
IntegrationAssertions.assertNotNull(info.getFlightInfo()); | ||
progress = info.getProgress(); | ||
IntegrationAssertions.assertTrue("progress is missing in finished query", progress.isPresent()); | ||
IntegrationAssertions.assertTrue("progress isn't 1.0 in finished query", | ||
Math.abs(progress.get() - 1.0) < Math.ulp(1.0)); | ||
IntegrationAssertions.assertFalse("expiration is set in finished query", info.getExpirationTime().isPresent()); | ||
IntegrationAssertions.assertFalse("descriptor is set in finished query", info.getFlightDescriptor().isPresent()); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POLL_FLIGHT_INFO
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in the original PR: apache@9fb0af3