singhpk234 commented on code in PR #1487: URL: https://github.com/apache/polaris/pull/1487#discussion_r2067079635
########## 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 */ Review Comment: does it makes sense to add a comment that the caller is expected to close the resources ? ########## extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcBasePersistenceImpl.java: ########## @@ -417,9 +415,17 @@ public <T> List<T> listEntities( // absence of transaction. String query = QueryGenerator.generateSelectQuery(ModelEntity.class, params); try { - List<PolarisBaseEntity> results = - datasourceOperations.executeSelect( - query, ModelEntity.class, ModelEntity::toEntity, entityFilter, limit); + List<PolarisBaseEntity> results = new ArrayList<>(); + datasourceOperations.executeSelectOverStream( + query, + new ModelEntity(), + stream -> { + stream + .map(ModelEntity::toEntity) + .filter(entityFilter) + .limit(limit) + .forEach(results::add); Review Comment: is there a way to do `toList()` ? ########## 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: interesting, if it's a SQLException shouldn't we throw it as SQLException to inspect the error code ? any other exception other than SQLException is considered as RTE for now in the caller. -- 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: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org