Documentation
¶
Overview ¶
Package io provides an interface for IO implementations along with a registry for registering IO implementations for different URI schemes.
Subpackages of this package provide implementations for cloud storage providers which will register themselves if imported. For instance, adding the following import:
import _ "github.com/apache/iceberg-go/io/gocloud"
Will register S3, GCS and Azure, and link all three cloud SDKs. Importing io/gocloud/s3, io/gocloud/gcs or io/gocloud/azure instead registers only that backend. The local filesystem (file:// and empty scheme) is always registered.
Index ¶
- Constants
- Variables
- func GetRegisteredSchemes() []string
- func LoadFSFunc(props map[string]string, location string) func(ctx context.Context) (IO, error)
- func MustRegister(scheme string, factory SchemeFactory)
- func Register(scheme string, factory SchemeFactory)
- func Unregister(scheme string)
- type BulkRemovableIO
- type FSOption
- type File
- type FileWriter
- type IO
- type ListableIO
- type LocalFS
- func (LocalFS) Create(ctx context.Context, name string) (FileWriter, error)
- func (LocalFS) Mkdir(name string) error
- func (LocalFS) MkdirAll(ctx context.Context, name string) error
- func (LocalFS) Open(_ context.Context, name string) (File, error)
- func (LocalFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (LocalFS) ReadFile(_ context.Context, name string) ([]byte, error)
- func (LocalFS) Remove(_ context.Context, name string) error
- func (LocalFS) RemoveAll(ctx context.Context, name string) error
- func (LocalFS) Rename(_ context.Context, oldpath, newpath string) error
- func (LocalFS) RenameNoReplace(_ context.Context, oldpath, newpath string) error
- func (LocalFS) Stat(_ context.Context, name string) (fs.FileInfo, error)
- func (LocalFS) WalkDir(ctx context.Context, root string, fn fs.WalkDirFunc) error
- func (LocalFS) WriteFile(ctx context.Context, name string, content []byte) error
- type MemFS
- func (m *MemFS) Create(ctx context.Context, name string) (FileWriter, error)
- func (m *MemFS) Open(_ context.Context, name string) (File, error)
- func (m *MemFS) Remove(_ context.Context, name string) error
- func (m *MemFS) WalkDir(ctx context.Context, root string, fn fs.WalkDirFunc) error
- func (m *MemFS) WriteFile(ctx context.Context, name string, content []byte) error
- type MkdirAllIO
- type ReadDirFile
- type ReadFileIO
- type Registry
- func (r *Registry) Clone() *Registry
- func (r *Registry) LoadFS(ctx context.Context, props map[string]string, location string) (IO, error)
- func (r *Registry) LoadFSFunc(props map[string]string, location string) func(ctx context.Context) (IO, error)
- func (r *Registry) MustRegister(scheme string, factory SchemeFactory)
- func (r *Registry) Names() []string
- func (r *Registry) Register(scheme string, factory SchemeFactory) error
- func (r *Registry) Unregister(scheme string)
- type RemoveAllIO
- type RenameIO
- type RenameNoReplaceIO
- type SchemeFactory
- type StatIO
- type WriteFileIO
Constants ¶
const ( S3Region = "s3.region" S3SessionToken = "s3.session-token" S3SecretAccessKey = "s3.secret-access-key" S3AccessKeyID = "s3.access-key-id" S3EndpointURL = "s3.endpoint" S3ProxyURI = "s3.proxy-uri" // S3ConnectTimeout accepts seconds as a number, such as "60" or "60.0", // or a Go duration string, such as "5s". S3ConnectTimeout = "s3.connect-timeout" // S3SignerURI is the legacy signing service base URI. REST catalogs default // to the table-scoped signing endpoint when no legacy endpoint is provided. S3SignerURI = "s3.signer.uri" // S3RemoteSigningEnabled enables remote signing without local AWS credentials. S3RemoteSigningEnabled = "s3.remote-signing-enabled" S3ForceVirtualAddressing = "s3.force-virtual-addressing" S3ClientRegion = "client.region" S3CompatMode = "s3.compat-mode" )
Constants for S3 configuration options
const ( GCSEndpoint = "gcs.endpoint" GCSServiceHost = "gcs.service.host" GCSKeyPath = "gcs.keypath" GCSJSONKey = "gcs.jsonkey" GCSCredType = "gcs.credtype" GCSUseJSONAPI = "gcs.usejsonapi" GCSOAuthToken = "gcs.oauth2.token" GCSOAuthExpiresAt = "gcs.oauth2.token-expires-at" GCSNoAuth = "gcs.no-auth" )
Constants for GCS configuration options
const ( ADLSSASTokenPrefix = "adls.sas-token." ADLSConnectionStringPrefix = "adls.connection-string." ADLSEndpoint = "adls.endpoint" ADLSProtocol = "adls.protocol" // ADLSManagedIdentityEnabled uses ManagedIdentityCredential directly when set // to "true", rather than the broader DefaultAzureCredential chain, which already // tries managed identity among its other sources. Pair it with ADLSClientID to // select a user-assigned managed identity; on its own it uses the system-assigned // managed identity. // // It is evaluated only after shared-key credentials, a SAS-token property for // the target hostname, a connection-string property for the target account // name, and a nonempty ADLSToken, all of which take precedence over it; if any // of them is configured, this flag has no effect. // // This property is specific to this implementation. Neither the Java nor the // PyIceberg implementation defines an equivalent property, so catalog properties // that set it will not carry over to them. ADLSManagedIdentityEnabled = "adls.auth.managed-identity.enabled" // ADLSClientID selects a user-assigned managed identity by client ID. It only // takes effect when ADLSManagedIdentityEnabled is "true"; on its own it is ignored. // // PyIceberg recognizes the same "adls.client-id" key but uses it for service // principal authentication, alongside "adls.client-secret" and "adls.tenant-id", // which it requires to be set together; see // https://py.iceberg.apache.org/configuration/#azure-data-lake. This // implementation defines neither of those, so the key is only ever read as a // user-assigned managed identity ID here. Java's AzureProperties defines no // "adls.client-id" at all. ADLSClientID = "adls.client-id" // ADLSToken is a static OAuth2 access token for Azure Storage, without the // "Bearer " prefix. A nonempty token takes precedence over managed identity // and the default credential chain, but not shared-key credentials, a SAS-token // property for the target hostname, or a connection-string property for the // target account name. An empty token is ignored. // // The token is not refreshed. Azure enforces its expiration; callers must // recreate the FileIO with a new token when it expires. ADLSToken = "adls.token" )
Constants for Azure configuration options
Variables ¶
var ( // ErrSchemeAlreadyRegistered indicates that a registry already has a factory for a scheme. ErrSchemeAlreadyRegistered = errors.New("io scheme already registered") // ErrInvalidSchemeFactory indicates that an attempt was made to register a nil factory. ErrInvalidSchemeFactory = errors.New("io scheme factory is nil") )
var (
ErrIOSchemeNotFound = errors.New("io scheme not registered")
)
Functions ¶
func GetRegisteredSchemes ¶ added in v0.5.0
func GetRegisteredSchemes() []string
GetRegisteredSchemes returns the names registered globally in sorted order.
func LoadFSFunc ¶ added in v0.4.0
LoadFSFunc constructs a lazy factory backed by the global scheme registry.
func MustRegister ¶ added in v0.8.0
func MustRegister(scheme string, factory SchemeFactory)
MustRegister registers a global scheme or panics. Use this from backend init functions. For registration errors instead of panics, create an independent registry and call Registry.Register.
func Register ¶ added in v0.5.0
func Register(scheme string, factory SchemeFactory)
Register adds a scheme factory to the global registry. As in earlier versions, a nil factory or duplicate scheme causes a panic.
func Unregister ¶ added in v0.5.0
func Unregister(scheme string)
Unregister removes a scheme from the global registry.
Types ¶
type BulkRemovableIO ¶ added in v0.6.0
type BulkRemovableIO interface {
IO
// DeleteFiles deletes all named files. Implementations should make a
// best-effort attempt to delete as many files as possible, returning
// the list of successfully deleted paths and a joined error
// (via [errors.Join]) for any individual failures.
//
// Missing files are not considered errors — if a path does not exist,
// it should be treated as a successful deletion.
//
// An empty paths slice is a no-op and must not error.
DeleteFiles(ctx context.Context, paths []string) (deleted []string, err error)
}
BulkRemovableIO is an optional interface for IO implementations that support deleting multiple files in a single batch operation. Cloud object stores (S3 DeleteObjects, GCS batch, Azure batch) can implement this for significantly better throughput than single-file Remove.
type FSOption ¶ added in v0.8.0
type FSOption func(*ioFS)
FSOption configures an IO adapter created by FS.
func WithNamePreprocessor ¶ added in v0.8.0
WithNamePreprocessor transforms filenames before FS normalizes leading slashes and passes them to the underlying fs.FS. It applies to Open, Remove, and ReadFile when available. A nil preprocessor leaves names unchanged. fn must be safe for concurrent use by multiple goroutines.
type File ¶
A File provides access to a single file. The File interface is the minimum implementation required for Iceberg to interact with a file. Directory files should also implement
type FileWriter ¶ added in v0.2.0
type FileWriter interface {
io.WriteCloser
io.ReaderFrom
}
A FileWriter represents an open writable file.
type IO ¶
type IO interface {
// Open opens the named file.
//
// Implementations may use ctx to bound the open; those backed by a
// plain io/fs.FS ignore it since fs.FS.Open takes no context. Reads on
// the returned File are not bound by ctx.
//
// When Open returns an error, it should be of type *PathError
// with the Op field set to "open", the Path field set to name,
// and the Err field describing the problem.
//
// Open should reject attempts to open names that do not satisfy
// fs.ValidPath(name), returning a *PathError with Err set to
// ErrInvalid or ErrNotExist.
Open(ctx context.Context, name string) (File, error)
// Remove removes the named file or (empty) directory. The context bounds
// the delete; local filesystem implementations ignore it.
//
// If there is an error, it will be of type *PathError.
// Implementations must be safe for concurrent use by multiple goroutines.
Remove(ctx context.Context, name string) error
}
IO is an interface to a hierarchical file system.
The IO interface is the minimum implementation required for a file system to utilize an iceberg table. A file system may implement additional interfaces, such as ReadFileIO, to provide additional or optimized functionality.
func FS ¶
FS wraps an io/fs.FS as an IO interface. It implements ReadFileIO if the underlying fsys supports fs.ReadFileFS or a context-aware ReadFile method. Options can configure name processing; see WithNamePreprocessor.
type ListableIO ¶ added in v0.6.0
type ListableIO interface {
IO
// WalkDir walks the file tree rooted at root, calling fn for each
// file or directory in the tree, including root. Paths passed to fn
// are full URIs consistent with the root's scheme and authority.
// Implementations should pass ctx to backend listing operations and stop
// traversal when it is canceled.
WalkDir(ctx context.Context, root string, fn fs.WalkDirFunc) error
}
ListableIO is the interface implemented by a file system that supports directory walking. This replaces the need for reflect-based access to internal file system structures (e.g., blob storage buckets).
The root parameter is a full URI (e.g., "s3://bucket/path" or "/local/path") as used throughout the iceberg-go codebase. The fn callback receives full URI paths consistent with the root's scheme and authority.
type LocalFS ¶
type LocalFS struct{}
LocalFS is an implementation of IO that implements interaction with the local file system.
func (LocalFS) RenameNoReplace ¶ added in v0.7.0
type MemFS ¶ added in v0.6.0
type MemFS struct {
// contains filtered or unexported fields
}
MemFS is a simple in-memory IO implementation used for testing and lightweight workloads. Files are stored per named bucket and persist for the lifetime of the process. Use the "mem://bucket/path" URI scheme to access files.
func NewMemFS ¶ added in v0.6.0
func NewMemFS() *MemFS
NewMemFS creates an initialized MemFS ready for use.
type MkdirAllIO ¶ added in v0.7.0
type MkdirAllIO interface {
IO
// MkdirAll should not raise an error if the directory already exists,
// and should create any parent directories in the path if they
// do not already exist. The context controls the operation where the
// implementation supports cancellation.
MkdirAll(ctx context.Context, path string) error
}
MkdirAllIO is an extension of IO interface that includes the MkdirAll method for creating a directory path recursively
type ReadDirFile ¶
type ReadDirFile interface {
File
// ReadDir read the contents of the directory and returns a slice
// of up to n DirEntry values in directory order. Subsequent calls
// on the same file will yield further DirEntry values.
//
// If n > 0, ReadDir returns at most n DirEntry structures. In this
// case, if ReadDir returns an empty slice, it will return a non-nil
// error explaining why.
//
// At the end of a directory, the error is io.EOF. (ReadDir must return
// io.EOF itself, not an error wrapping io.EOF.)
//
// If n <= 0, ReadDir returns all the DirEntry values from the directory
// in a single slice. In this case, if ReadDir succeeds (reads all the way
// to the end of the directory), it returns the slice and a nil error.
// If it encounters an error before the end of the directory, ReadDir
// returns the DirEntry list read until that point and a non-nil error.
ReadDir(n int) ([]fs.DirEntry, error)
}
A ReadDirFile is a directory file whose entries can be read with the ReadDir method. Every directory file should implement this interface. (It is permissible for any file to implement this interface, but if so ReadDir should return an error for non-directories.)
type ReadFileIO ¶
type ReadFileIO interface {
IO
// ReadFile reads the named file and returns its contents. The context bounds
// remote reads; local implementations and those backed by fs.ReadFileFS may
// ignore it.
// A successful call returns a nil error, not io.EOF.
// (Because ReadFile reads the whole file, the expected EOF
// from the final Read is not treated as an error to be reported.)
//
// The caller is permitted to modify the returned byte slice.
// This method should return a copy of the underlying data.
ReadFile(ctx context.Context, name string) ([]byte, error)
}
ReadFileIO is the interface implemented by a file system that provides an optimized implementation of ReadFile.
type Registry ¶ added in v0.8.0
type Registry struct {
// contains filtered or unexported fields
}
Registry manages FileIO factories for URI schemes. A registry may be used by multiple goroutines. Factories run without the registry lock held, so they may register other schemes or load additional FileIO instances.
func NewRegistry ¶ added in v0.8.0
func NewRegistry() *Registry
NewRegistry creates an independent snapshot of the globally registered schemes, including cloud providers already registered through side-effect imports. Future registrations in either registry do not affect the other. Called from a package-level var initializer, it can miss backends that the calling package does not import.
func (*Registry) Clone ¶ added in v0.8.0
Clone returns an independent copy of a registry's factory registrations. Factories themselves are shared, but the registration maps and locks are not.
func (*Registry) LoadFS ¶ added in v0.8.0
func (r *Registry) LoadFS(ctx context.Context, props map[string]string, location string) (IO, error)
LoadFS loads a FileIO using only this registry's scheme factories. If location is empty, the warehouse property is used instead.
func (*Registry) LoadFSFunc ¶ added in v0.8.0
func (r *Registry) LoadFSFunc(props map[string]string, location string) func(ctx context.Context) (IO, error)
LoadFSFunc constructs a lazy factory backed by this registry. It keeps the registry selection even when other schemes are registered globally later.
func (*Registry) MustRegister ¶ added in v0.8.0
func (r *Registry) MustRegister(scheme string, factory SchemeFactory)
MustRegister registers a scheme or panics. It is intended for provider init functions where failing to register a required backend is unrecoverable.
func (*Registry) Register ¶ added in v0.8.0
func (r *Registry) Register(scheme string, factory SchemeFactory) error
Register adds a scheme factory. Unlike MustRegister, it returns errors for invalid or duplicate registrations rather than panicking.
func (*Registry) Unregister ¶ added in v0.8.0
Unregister removes a scheme from this registry only.
type RemoveAllIO ¶ added in v0.7.0
type RemoveAllIO interface {
IO
// RemoveAll removes the named path and any children recursively. The context
// controls the operation where the implementation supports cancellation. A
// canceled operation may leave the tree partially removed. The returned error
// may wrap ctx.Err(), so use errors.Is to check for cancellation.
RemoveAll(ctx context.Context, name string) error
}
RemoveAllIO is an extension of IO interface that includes the RemoveAll method for removing a file path and any children recursively
type RenameIO ¶ added in v0.7.0
type RenameIO interface {
IO
// Rename moves one file or object from oldpath to newpath. The context
// controls the operation where the implementation supports cancellation.
Rename(ctx context.Context, oldpath, newpath string) error
}
RenameIO is an extension of IO interface that includes the Rename method for renaming (moving) one file or object. This is atomic on a local filesystem but is not atomic in other implementations like blob stores
type RenameNoReplaceIO ¶ added in v0.7.0
type RenameNoReplaceIO interface {
IO
// RenameNoReplace moves one file or object only if newpath does not exist.
// The context controls the operation where the implementation supports cancellation.
RenameNoReplace(ctx context.Context, oldpath, newpath string) error
}
RenameNoReplaceIO is an extension of IO interface that includes the RenameNoReplace method for moving files only when the destination path does not already exist. Implementations may require oldpath and newpath to live on the same filesystem. This is atomic on a local filesystem but is not atomic in other implementations like blob stores
type SchemeFactory ¶ added in v0.5.0
SchemeFactory creates an IO implementation for a URI and its properties.
type StatIO ¶ added in v0.7.0
type StatIO interface {
IO
// Stat returns a FileInfo describing the named file or directory, or an error
// satisfying errors.Is(err, fs.ErrNotExist) if the file does not exist. The
// context bounds remote stat operations; local filesystem implementations may
// ignore it.
Stat(ctx context.Context, path string) (fs.FileInfo, error)
}
StatIO is an extension of IO interface that includes the Stat method for retrieving file or directory information
type WriteFileIO ¶ added in v0.2.0
type WriteFileIO interface {
IO
// Create attempts to create the named file and return a writer
// for it. Implementations may use ctx to bound creation and writes
// performed through the returned writer.
Create(ctx context.Context, name string) (FileWriter, error)
// WriteFile writes p to the named file.
WriteFile(ctx context.Context, name string, p []byte) error
}
WriteFileIO is the interface implemented by a file system that provides an optimized implementation of WriteFile
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gocloud registers every gocloud.dev-backed FileIO implementation and therefore links the AWS, Google Cloud and Azure SDKs.
|
Package gocloud registers every gocloud.dev-backed FileIO implementation and therefore links the AWS, Google Cloud and Azure SDKs. |
|
azure
Package azure provides the FileIO backend for Azure Data Lake Storage and Blob Storage.
|
Package azure provides the FileIO backend for Azure Data Lake Storage and Blob Storage. |
|
blobfs
Package blobfs implements the iceberg-go/io FileIO interfaces on top of a gocloud.dev blob bucket.
|
Package blobfs implements the iceberg-go/io FileIO interfaces on top of a gocloud.dev blob bucket. |
|
gcs
Package gcs provides the FileIO backend for Google Cloud Storage.
|
Package gcs provides the FileIO backend for Google Cloud Storage. |
|
s3
Package s3 provides the FileIO backend for S3 and S3-compatible object stores.
|
Package s3 provides the FileIO backend for S3 and S3-compatible object stores. |