external

package
v0.0.0-debug-20260702 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColumnCntLargerErrorInfo = "the table column is larger than input data column"
)
View Source
const (
	HiveDefaultPartition = "__HIVE_DEFAULT_PARTITION__"
)
View Source
const JsonNull = "\\N"

Variables

View Source
var (
	OneBatchMaxRow   = int(options.DefaultBlockMaxRows)
	S3ParallelMaxnum = 10
)
View Source
var (
	STATEMENT_ACCOUNT = "account"
)

Functions

func BuildHivePartitionListCacheKey

func BuildHivePartitionListCacheKey(param *tree.ExternParam, accountID uint32, basePath, prefix string) string

func BuildHivePartitionListCacheKeyPrefix

func BuildHivePartitionListCacheKeyPrefix(param *tree.ExternParam, accountID uint32, basePath string) string

func ClassifyFilters

func ClassifyFilters(
	tableDef *plan.TableDef,
	filters []*plan.Expr,
	partColSet map[string]bool,
) (partitionFilters, filePathFilters, rowFilters []*plan.Expr)

ClassifyFilters splits a filter list into three disjoint groups:

  • partitionFilters: only reference partition columns (also copied to rowFilters)
  • filePathFilters: only reference filepath virtual columns (see filePathColSet: __mo_filepath only)
  • rowFilters: everything else, plus partition filters for double-filtering safety

func ExtractPartitionValues

func ExtractPartitionValues(filePath, basePath string, partCols []string) (map[string]string, error)

ExtractPartitionValues parses partition key=value segments from a file path relative to basePath. Both paths are normalized internally.

func FilterFileList added in v0.7.0

func FilterFileList(ctx context.Context, node *plan.Node, proc *process.Process, fileList []string, fileSize []int64) ([]string, []int64, error)

func IsHiddenFile

func IsHiddenFile(name string) bool

IsHiddenFile returns true for files/dirs starting with '.' or '_'.

func IsParquetFile

func IsParquetFile(name string) bool

IsParquetFile returns true for files with .parquet or .snappy.parquet suffix.

func ReadFileOffset added in v0.7.0

func ReadFileOffset(param *tree.ExternParam, mcpu int, fileSize int64, visibleCols []*plan.ColDef) ([]int64, error)

func ResetHivePartitionListCacheForTest

func ResetHivePartitionListCacheForTest()

Types

type CsvReader

type CsvReader struct {
	// contains filtered or unexported fields
}

CsvReader handles CSV and JSONLINE formats.

func NewCsvReader

func NewCsvReader(param *ExternalParam, proc *process.Process) (*CsvReader, error)

NewCsvReader creates a CsvReader. JSONLINE invalid config returns explicit error to match existing semantics.

func (*CsvReader) Close

func (r *CsvReader) Close() error

func (*CsvReader) Open

func (r *CsvReader) Open(param *ExternalParam, proc *process.Process) (fileEmpty bool, err error)

func (*CsvReader) ReadBatch

func (r *CsvReader) ReadBatch(
	ctx context.Context, buf *batch.Batch,
	proc *process.Process, analyzer process.Analyzer,
) (fileFinished bool, err error)

type DiscoverOptions

type DiscoverOptions struct {
	MaxPartitions   int
	WarnPartitions  int
	MaxListCalls    int
	ListConcurrency int
	CacheTTL        time.Duration
	CacheKeyPrefix  string
	CacheMaxEntries int
	CacheMaxBytes   int64
	// contains filtered or unexported fields
}

type ExFileparam added in v0.7.0

type ExFileparam struct {
	End       bool
	FileCnt   int
	FileFin   int
	FileIndex int
	Filepath  string
}

type ExParam added in v0.7.0

type ExParam struct {
	Fileparam *ExFileparam
	Filter    *FilterParam
	// contains filtered or unexported fields
}

type ExParamConst added in v0.7.0

type ExParamConst struct {
	ParallelLoad           bool
	LoadEmptyNumericAsZero bool
	StrictSqlMode          bool
	Close                  byte

	Idx           int
	ColumnListLen int32 // load ...  (col1, col2 , col3), ColumnListLen is 3
	CreateSql     string

	// letter case: origin
	Attrs           []plan.ExternAttr
	Cols            []*plan.ColDef
	FileList        []string
	FileSize        []int64
	FileOffset      []int64
	FileOffsetTotal []*pipeline.FileOffset
	// Optional Parquet row group shards. Empty means whole-file scan.
	ParquetRowGroupShards []*pipeline.ParquetRowGroupShard
	Ctx                   context.Context
	Extern                *tree.ExternParam
	ClusterTable          *plan.ClusterTable
	// contains filtered or unexported fields
}

type External

type External struct {
	Es *ExternalParam

	vm.OperatorBase
	colexec.Projection
	// contains filtered or unexported fields
}

func NewArgument added in v1.2.0

func NewArgument() *External

func (*External) Call

func (external *External) Call(proc *process.Process) (vm.CallResult, error)

func (*External) ExecProjection

func (external *External) ExecProjection(proc *process.Process, input *batch.Batch) (*batch.Batch, error)

func (*External) Free

func (external *External) Free(proc *process.Process, pipelineFailed bool, err error)

func (*External) GetOperatorBase

func (external *External) GetOperatorBase() *vm.OperatorBase

func (*External) OpType

func (external *External) OpType() vm.OpType

func (*External) Prepare

func (external *External) Prepare(proc *process.Process) error

func (*External) Release

func (external *External) Release()

func (*External) Reset

func (external *External) Reset(proc *process.Process, pipelineFailed bool, err error)

func (*External) String

func (external *External) String(buf *bytes.Buffer)

func (External) TypeName

func (external External) TypeName() string

func (*External) WithEs

func (external *External) WithEs(es *ExternalParam) *External

type ExternalFileReader

type ExternalFileReader interface {
	// Open opens a file and initializes internal state.
	// fileEmpty=true means the file is empty (e.g. 0-row Parquet),
	// Call should Close then finishCurrentFile and continue to next file.
	Open(param *ExternalParam, proc *process.Process) (fileEmpty bool, err error)

	// ReadBatch reads one batch of data into buf.
	// Returns true when the current file is fully read.
	ReadBatch(ctx context.Context, buf *batch.Batch, proc *process.Process, analyzer process.Analyzer) (fileFinished bool, err error)

	// Close closes the current file and releases resources.
	Close() error
}

ExternalFileReader is the unified interface for reading external files. Each format (CSV/Parquet/ZoneMap) implements this interface independently.

Lifecycle: NewXxxReader() → Open() → ReadBatch()* → Close() → Open() → ... Reader saves param reference in Open, subsequent methods access it via r.param.

type ExternalParam

type ExternalParam struct {
	// Externally passed parameters that will not change
	ExParamConst
	// Inner parameters
	ExParam
}

Use for External table scan param

type FilterParam added in v0.7.0

type FilterParam struct {
	FilterExpr *plan.Expr
	AuxIdCnt   int32 // saved from AssignAuxIdForExpr in Prepare, reused at runtime
	// contains filtered or unexported fields
}

type HivePartSegment

type HivePartSegment struct {
	Key   string
	Value string
}

HivePartSegment is the parsed result of a single Hive partition directory segment.

func ParseHivePartitionSegment

func ParseHivePartitionSegment(segment string) (seg HivePartSegment, isHive bool, err error)

ParseHivePartitionSegment parses a directory segment like "year=2024" into key/value. Keys stay in the raw path domain and are not URL-decoded. Values are decoded exactly once for SQL-visible partition values; callers must continue to use raw paths when listing or opening files.

Returns:

  • (seg, true, nil): valid key=value segment (value may be empty string)
  • (_, false, nil): not a key=value format (caller treats as non-partition dir)

type HivePartitionListCacheEntry

type HivePartitionListCacheEntry struct {
	Entries  []fileservice.DirEntry
	ExpireAt time.Time
	SizeHint int64
	// contains filtered or unexported fields
}

type ListDirFunc

type ListDirFunc func(ctx context.Context, prefix string) iter.Seq2[*fileservice.DirEntry, error]

ListDirFunc abstracts directory listing for testability and S3/local duality.

func NewListDirFunc

func NewListDirFunc(param *tree.ExternParam) ListDirFunc

NewListDirFunc creates a ListDirFunc backed by GetForETLWithType.

type MatchResult

type MatchResult int

MatchResult is a three-state result for partition value comparison.

const (
	MatchTrue    MatchResult = iota // definitely matches
	MatchFalse                      // definitely does not match (safe to prune)
	MatchUnknown                    // cannot determine (must keep directory)
)

type ParquetHandler added in v1.2.0

type ParquetHandler struct {
	// contains filtered or unexported fields
}

type ParquetReader

type ParquetReader struct {
	// contains filtered or unexported fields
}

ParquetReader handles Parquet format files.

func NewParquetReader

func NewParquetReader(param *ExternalParam, proc *process.Process) *ParquetReader

func (*ParquetReader) Close

func (r *ParquetReader) Close() error

func (*ParquetReader) Open

func (r *ParquetReader) Open(param *ExternalParam, proc *process.Process) (fileEmpty bool, err error)

func (*ParquetReader) ReadBatch

func (r *ParquetReader) ReadBatch(
	ctx context.Context, buf *batch.Batch,
	proc *process.Process, analyzer process.Analyzer,
) (fileFinished bool, err error)

type ParseLineHandler

type ParseLineHandler struct {
	// contains filtered or unexported fields
}

type PartitionAnd

type PartitionAnd struct {
	Children []PartitionPruneExpr
}

func (*PartitionAnd) EvalPartial

func (a *PartitionAnd) EvalPartial(values map[string]string, colTypes map[string]tree.HivePartColType) MatchResult

func (*PartitionAnd) ReferencedCols

func (a *PartitionAnd) ReferencedCols() map[string]bool

type PartitionAtom

type PartitionAtom struct {
	ColName string
	Op      PartitionOp
	Values  []string
}

func (*PartitionAtom) EvalPartial

func (a *PartitionAtom) EvalPartial(values map[string]string, colTypes map[string]tree.HivePartColType) MatchResult

func (*PartitionAtom) ReferencedCols

func (a *PartitionAtom) ReferencedCols() map[string]bool

type PartitionDiscoveryResult

type PartitionDiscoveryResult struct {
	Files          []PartitionFileEntry
	PartitionCount int
	PrunedCount    int
	ListCalls      int

	CacheHits             int
	CacheMisses           int
	ListConcurrency       int
	DiscoveryDuration     time.Duration
	InferredPartitionCols []string
	DiscoveredFiles       int
	DiscoveredBytes       int64
	PrunedFiles           int
	PrunedBytes           int64
	DirectPrefixHits      int
	DirectPrefixMisses    int
	// contains filtered or unexported fields
}

PartitionDiscoveryResult holds the outcome of Hive partition discovery.

func DiscoverHivePartitions

func DiscoverHivePartitions(
	ctx context.Context,
	listDir ListDirFunc,
	basePath string,
	partCols []string,
	colTypes []tree.HivePartColType,
	predicates []PartitionPredicate,
) (*PartitionDiscoveryResult, error)

DiscoverHivePartitions performs recursive list-and-filter partition discovery.

func DiscoverHivePartitionsWithPruneExpr

func DiscoverHivePartitionsWithPruneExpr(
	ctx context.Context,
	listDir ListDirFunc,
	basePath string,
	partCols []string,
	colTypes []tree.HivePartColType,
	pruneExpr PartitionPruneExpr,
	opts *DiscoverOptions,
) (*PartitionDiscoveryResult, error)

type PartitionFileEntry

type PartitionFileEntry struct {
	FilePath string
	FileSize int64
}

PartitionFileEntry represents a discovered file within a Hive partition structure.

type PartitionOp

type PartitionOp int
const (
	PartOpEq PartitionOp = iota
	PartOpIn
	PartOpLt
	PartOpLe
	PartOpGt
	PartOpGe
	PartOpBetween
	PartOpIsNull
	PartOpIsNotNull
)

type PartitionOr

type PartitionOr struct {
	Children []PartitionPruneExpr
}

func (*PartitionOr) EvalPartial

func (o *PartitionOr) EvalPartial(values map[string]string, colTypes map[string]tree.HivePartColType) MatchResult

func (*PartitionOr) ReferencedCols

func (o *PartitionOr) ReferencedCols() map[string]bool

type PartitionPredicate

type PartitionPredicate struct {
	ColName string
	Op      PartitionOp
	Values  []string
}

PartitionPredicate represents a filter hint for partition pruning.

func ExtractPartitionPredicatesFromExprs

func ExtractPartitionPredicatesFromExprs(
	tableDef *plan.TableDef,
	partFilters []*plan.Expr,
	partColSet map[string]bool,
) []PartitionPredicate

ExtractPartitionPredicatesFromExprs converts partition filter expressions into PartitionPredicate hints for directory-level pruning. Supports col = const (PartOpEq) and col IN (const, ...) (PartOpIn). Expressions that cannot be structurally decomposed are silently skipped.

Note: After optimizer constant-folding (rule.ConstantFold applies to all nodes), IN lists may be folded from Expr_List to Expr_Vec. Both forms are handled.

type PartitionPruneExpr

type PartitionPruneExpr interface {
	EvalPartial(values map[string]string, colTypes map[string]tree.HivePartColType) MatchResult
	ReferencedCols() map[string]bool
}

PartitionPruneExpr is a conservative, directory-level predicate tree. EvalPartial is allowed to return MatchUnknown whenever the currently-known partition values are insufficient or SQL semantics cannot be reproduced exactly from path strings. Only MatchFalse may prune a directory.

func ExtractPartitionPruneExprFromExprs

func ExtractPartitionPruneExprFromExprs(
	tableDef *plan.TableDef,
	partFilters []*plan.Expr,
	partColSet map[string]bool,
) PartitionPruneExpr

type ZonemapFileparam added in v0.7.0

type ZonemapFileparam struct {
	// contains filtered or unexported fields
}

type ZonemapReader

type ZonemapReader struct {
	// contains filtered or unexported fields
}

ZonemapReader handles MO internal result files (RESULT_SCAN).

func NewZonemapReader

func NewZonemapReader(param *ExternalParam, proc *process.Process) *ZonemapReader

NewZonemapReader creates a ZonemapReader. zonemappable is computed here since only ZonemapReader uses it.

func (*ZonemapReader) Close

func (r *ZonemapReader) Close() error

func (*ZonemapReader) Open

func (r *ZonemapReader) Open(param *ExternalParam, proc *process.Process) (fileEmpty bool, err error)

func (*ZonemapReader) ReadBatch

func (r *ZonemapReader) ReadBatch(
	ctx context.Context, buf *batch.Batch,
	proc *process.Process, analyzer process.Analyzer,
) (fileFinished bool, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL