Documentation
¶
Index ¶
- Constants
- Variables
- func CSVHeaders(reader *bufio.Reader, maxRowSizeBytes int64) (headers []string, bytesReadForHeader int64, err error)
- func GetObjectKeyFromRequest(request *Request) string
- func MarshalS3Cursor(cursor *S3Cursor) (string, *framework.Error)
- func NewAdapter(client Client) framework.Adapter[Config]
- func StreamingCSVToPage(streamReader *bufio.Reader, headers []string, pageSize int64, ...) (objects []map[string]any, bytesReadFromDataStream int64, hasNext bool, ...)
- type Adapter
- func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response
- func (a *Adapter) RequestPageFromDatasource(ctx context.Context, request *framework.Request[Config]) framework.Response
- func (a *Adapter) ValidateGetPageRequest(ctx context.Context, request *framework.Request[Config]) *framework.Error
- type Auth
- type Client
- type Config
- type Datasource
- type Request
- type Response
- type S3Cursor
- type S3Handler
- func (s *S3Handler) FileExists(ctx context.Context, bucket string, key string) (*s3.HeadObjectOutput, error)
- func (s *S3Handler) GetFileSize(ctx context.Context, bucket string, key string) (int64, error)
- func (s *S3Handler) GetObjectStream(ctx context.Context, bucket string, key string, rangeHeader *string) (*s3.GetObjectOutput, error)
Constants ¶
const FileTypeCSV = "csv"
Variables ¶
var ( DefaultFileType = FileTypeCSV SupportedFileTypes = map[string]struct{}{FileTypeCSV: {}} )
var ( UTF8BOM = []byte{0xEF, 0xBB, 0xBF} UTF16LEBOM = []byte{0xFF, 0xFE} UTF16BEBOM = []byte{0xFE, 0xFF} UTF32LEBOM = []byte{0xFF, 0xFE, 0x00, 0x00} UTF32BEBOM = []byte{0x00, 0x00, 0xFE, 0xFF} )
BOM (Byte Order Mark) patterns for different encodings.
var ErrEmptyOrMissing = errors.New("empty or missing")
Functions ¶
func CSVHeaders ¶ added in v1.44.0
func GetObjectKeyFromRequest ¶
func MarshalS3Cursor ¶ added in v1.67.0
MarshalS3Cursor marshals the cursor into a base64 encoded JSON string.
func NewAdapter ¶
NewAdapter instantiates a new Adapter.
func StreamingCSVToPage ¶ added in v1.44.0
Types ¶
type Adapter ¶
type Adapter struct {
Client Client
}
Adapter implements the framework.Adapter interface to query pages of objects from datasources.
func (*Adapter) GetPage ¶
func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response
GetPage is called by SGNL's ingestion service to query a page of objects from a datasource.
type Client ¶
type Client interface {
GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
}
Client is a client that allows querying the datasource which contains JSON objects.
type Config ¶
type Config struct {
// Common configuration
*config.CommonConfig
// Region is the AWS region to query.
Region string `json:"region"`
// Bucket is the AWS S3 bucket containing the files with entity data.
Bucket string `json:"bucket"`
// Prefix is the prefix of the path containing the files with entity data.
Prefix string `json:"prefix"`
// FileType is the extension of the files containing the entity data.
// This defaults to "csv".
FileType *string `json:"fileType,omitempty"`
}
type Datasource ¶
type Request ¶
type Request struct {
Auth
// Bucket is the AWS S3 bucket containing the files with entity data.
Bucket string
// PathPrefix is the prefix of the path containing the files with entity data.
PathPrefix string
// FileType is the extension of the files containing the entity data.
FileType string
// PageSize is the maximum number of objects to return from the entity.
PageSize int64
// EntityExternalID is the external ID of the entity.
// The external ID should match the file name.
EntityExternalID string
// Cursor identifies the first object of the page to return, as returned by
// the last request for the entity.
// nil in the request for the first page.
Cursor *S3Cursor
// RequestTimeoutSeconds is the timeout duration for requests made to datasources.
// This should be set to the number of seconds to wait before timing out.
RequestTimeoutSeconds int
// Ordered is a boolean that indicates whether the results should be ordered.
Ordered bool
// AttributeConfig is the list of attributes requested by the datasource.
AttributeConfig []*framework.AttributeConfig
}
Request is a request to the datasource.
type Response ¶
type Response struct {
// StatusCode is an HTTP status code.
StatusCode int
// RetryAfterHeader is the Retry-After response HTTP header, if set.
RetryAfterHeader string
// Objects is the list of items returned by the datasource.
// May be empty.
Objects []map[string]any
// NextCursor is the cursor that identifies the first object of the next page.
// nil if this is the last page in this full sync.
NextCursor *S3Cursor
}
Response is a response returned by the datasource.
type S3Cursor ¶ added in v1.67.0
type S3Cursor struct {
// Cursor is the byte position offset in the file where the next S3 fetch should start.
Cursor *int64 `json:"cursor,omitempty"`
// Headers contains the parsed CSV headers from the first page.
// Cached to avoid re-fetching headers on subsequent pages.
Headers []string `json:"headers,omitempty"`
// Remainder contains unprocessed bytes from the previous fetch.
// These bytes are prepended to the next S3 fetch to avoid data loss.
Remainder []byte `json:"remainder,omitempty"`
}
S3Cursor contains pagination state for S3 CSV files. Headers are cached to avoid re-fetching on subsequent pages.
func UnmarshalS3Cursor ¶ added in v1.67.0
UnmarshalS3Cursor unmarshals the cursor from a base64 encoded JSON string. Returns nil cursor if the input is empty.
func (*S3Cursor) MarshalLogObject ¶ added in v1.67.0
func (c *S3Cursor) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements zapcore.ObjectMarshaler to control cursor logging. Logs metadata (byte position, headers count, remainder length) without exposing actual data.