eric-maynard commented on code in PR #1487: URL: https://github.com/apache/polaris/pull/1487#discussion_r2067151744
########## extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/ResultSetIterator.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.polaris.extension.persistence.relational.jdbc; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; +import org.apache.polaris.extension.persistence.relational.jdbc.models.Converter; + +/** Used to wrap a ResultSet and to build a stream from the data it contains */ +public class ResultSetIterator<T> implements Iterator<T> { + private final ResultSet resultSet; + private final Converter<T> converterInstance; + private boolean hasNext; + + public ResultSetIterator(ResultSet resultSet, Converter<T> converterInstance) { + this.resultSet = resultSet; + this.converterInstance = converterInstance; + advance(); + } + + private void advance() { + try { + hasNext = resultSet.next(); + } catch (SQLException e) { + hasNext = false; + throw new RuntimeException(e); Review Comment: So the real problem here is `ResultSetIterator.next()`, which can't throw an exception so long as we're implementing `Iterator`. For now I'll have the constructor throw a `SQLException` so we have a chance of finding a `SQLException`, but we'd still wrap `SQLExceptions` that happen after the first `ResultSet.next()` call. If that's an issue, we can move away from implementing Iterator or fix the caller to unwrap the exception. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
