Class Utils

Object
io.delta.kernel.internal.util.Utils

@Evolving public class Utils extends Object
Various utility methods to help the connectors work with data objects returned by Kernel
Since:
3.0.0
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • singletonCloseableIterator

      public static <T> CloseableIterator<T> singletonCloseableIterator(T elem)
      Utility method to create a singleton CloseableIterator.
      Type Parameters:
      T - Element type.
      Parameters:
      elem - Element to create iterator with.
      Returns:
      A CloseableIterator with just one element.
    • toCloseableIterator

      public static <T> CloseableIterator<T> toCloseableIterator(Iterator<T> iter)
      Convert a Iterator to CloseableIterator. Useful when passing normal iterators for arguments that require CloseableIterator type.
      Type Parameters:
      T - Element type
      Parameters:
      iter - Iterator instance
      Returns:
      A CloseableIterator wrapping the given Iterator
    • closeCloseables

      public static void closeCloseables(AutoCloseable... closeables)
      Close the given one or more AutoCloseables. AutoCloseable.close() will be called on all given non-null closeables. Will throw unchecked RuntimeException if an error occurs while closing. If multiple closeables causes exceptions in closing, the exceptions will be added as suppressed to the main exception that is thrown.
      Parameters:
      closeables -
    • closeCloseablesSilently

      public static void closeCloseablesSilently(AutoCloseable... closeables)
      Close the given list of AutoCloseable objects. Any exception thrown is silently ignored.
      Parameters:
      closeables -
    • intoRows

      public static CloseableIterator<Row> intoRows(CloseableIterator<FilteredColumnarBatch> sourceBatches)
      Convert a ClosableIterator of FilteredColumnarBatch into a CloseableIterator of Row
    • flatten

      public static <T> CloseableIterator<T> flatten(CloseableIterator<CloseableIterator<T>> nestedIterator)
      Flattens a nested CloseableIterator structure into a single flat iterator. This method takes an iterator of iterators (nested structure) and flattens it into a single iterator that yields all elements from all inner iterators in sequence.

      Important: Callers must call Closeable.close() on the returned iterator even if it is not fully consumed, to ensure all inner iterators are properly closed and resources are released.

      Type Parameters:
      T - The type of elements in the inner iterators
      Parameters:
      nestedIterator - An iterator of iterators to flatten
      Returns:
      A new CloseableIterator that flattens all nested iterators
    • iteratorLast

      public static <T> Optional<T> iteratorLast(CloseableIterator<T> iterator)
      Returns the last element from the given CloseableIterator, if present.

      This method iterates through all elements of the iterator to find the last one. Once iteration is complete, the iterator is automatically closed to release any underlying resources.

      Type Parameters:
      T - The type of elements in the iterator
      Parameters:
      iterator - The iterator to get the last element from
      Returns:
      An Optional containing the last element, or Optional.empty() if the iterator is empty.
      Throws:
      UncheckedIOException - If an IOException occurs while closing the iterator.
    • resolvePath

      public static String resolvePath(Engine engine, String path)