Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new Remap interface to relations #71

Merged
merged 17 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions plan/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,46 +71,65 @@ type Builder interface {
// from the output.

Project(input Rel, exprs ...expr.Expression) (*ProjectRel, error)
// Deprecated: Use Project(...).Remap() instead.
ProjectRemap(input Rel, remap []int32, exprs ...expr.Expression) (*ProjectRel, error)
// Deprecated: Use AggregateColumns(...).Remap() instead.
AggregateColumnsRemap(input Rel, remap []int32, measures []AggRelMeasure, groupByCols ...int32) (*AggregateRel, error)
AggregateColumns(input Rel, measures []AggRelMeasure, groupByCols ...int32) (*AggregateRel, error)
// Deprecated: Use AggregateExprs(...).Remap() instead.
AggregateExprsRemap(input Rel, remap []int32, measures []AggRelMeasure, groups ...[]expr.Expression) (*AggregateRel, error)
AggregateExprs(input Rel, measures []AggRelMeasure, groups ...[]expr.Expression) (*AggregateRel, error)
// Deprecated: Use CreateTableAsSelect(...).Remap() instead.
CreateTableAsSelectRemap(input Rel, remap []int32, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error)
CreateTableAsSelect(input Rel, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error)
// Deprecated: Use Cross(...).Remap() instead.
CrossRemap(left, right Rel, remap []int32) (*CrossRel, error)
Cross(left, right Rel) (*CrossRel, error)
// FetchRemap constructs a fetch relation providing an offset (skipping some
// number of rows) and a count (restricting output to a maximum number of
// rows). If count is FETCH_COUNT_ALL_RECORDS (-1) all records will be
// returned. Similar to Fetch but allows for reordering and restricting the
// returned columns.
//
// Deprecated: Use Fetch(...).Remap() instead.
FetchRemap(input Rel, offset, count int64, remap []int32) (*FetchRel, error)
// Fetch constructs a fetch relation providing an offset (skipping some number of
// rows) and a count (restricting output to a maximum number of rows). If count
// is FETCH_COUNT_ALL_RECORDS (-1) all records will be returned.
Fetch(input Rel, offset, count int64) (*FetchRel, error)
// Deprecated: Use Filter(...).Remap() instead.
FilterRemap(input Rel, condition expr.Expression, remap []int32) (*FilterRel, error)
Filter(input Rel, condition expr.Expression) (*FilterRel, error)
// Deprecated: Use JoinAndFilter(...).Remap() instead.
JoinAndFilterRemap(left, right Rel, condition, postJoinFilter expr.Expression, joinType JoinType, remap []int32) (*JoinRel, error)
// Deprecated: Use Fetch(...).Remap() instead.
JoinAndFilter(left, right Rel, condition, postJoinFilter expr.Expression, joinType JoinType) (*JoinRel, error)
// Deprecated: Use Join(...).Remap() instead.
JoinRemap(left, right Rel, condition expr.Expression, joinType JoinType, remap []int32) (*JoinRel, error)
Join(left, right Rel, condition expr.Expression, joinType JoinType) (*JoinRel, error)
// Deprecated: Use NamedScan(...).Remap() instead.
NamedScanRemap(tableName []string, schema types.NamedStruct, remap []int32) (*NamedTableReadRel, error)
NamedScan(tableName []string, schema types.NamedStruct) *NamedTableReadRel
// Deprecated: Use NamedWrite(...).Remap() instead.
NamedWriteRemap(input Rel, op WriteOp, tableName []string, schema types.NamedStruct, remap []int32) (*NamedTableWriteRel, error)
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
// NamedWrite performs the given write operation from the input relation over a named table.
NamedWrite(input Rel, op WriteOp, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error)
// NamedInsert inserts data from the input relation into a named table.
NamedInsert(input Rel, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error)
// NamedDelete deletes rows from a specified named table based on the
// provided input relation, which typically includes conditions that filter
// the rows to delete.
NamedDelete(input Rel, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error)
// Deprecated: Use VirtualTable(...).Remap() instead.
VirtualTableRemap(fields []string, remap []int32, values ...expr.StructLiteralValue) (*VirtualTableReadRel, error)
VirtualTable(fields []string, values ...expr.StructLiteralValue) (*VirtualTableReadRel, error)
// Deprecated: Use VirtualTableFromExpr(...).Remap() instead.
VirtualTableFromExprRemap(fieldNames []string, remap []int32, values ...expr.VirtualTableExpressionValue) (*VirtualTableReadRel, error)
VirtualTableFromExpr(fieldNames []string, values ...expr.VirtualTableExpressionValue) (*VirtualTableReadRel, error)
// Deprecated: Use Sort(...).Remap() instead.
SortRemap(input Rel, remap []int32, sorts ...expr.SortField) (*SortRel, error)
Sort(input Rel, sorts ...expr.SortField) (*SortRel, error)
// Deprecated: Use Set(...).Remap() instead.
SetRemap(op SetOp, remap []int32, inputs ...Rel) (*SetRel, error)
Set(op SetOp, inputs ...Rel) (*SetRel, error)

Expand Down Expand Up @@ -487,12 +506,16 @@ func (b *builder) NamedWriteRemap(input Rel, op WriteOp, tableName []string, sch
}, nil
}

func (b *builder) NamedWrite(input Rel, op WriteOp, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error) {
return b.NamedWriteRemap(input, op, tableName, schema, nil)
}

func (b *builder) NamedInsert(input Rel, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error) {
return b.NamedWriteRemap(input, WriteOpInsert, tableName, schema, nil)
return b.NamedWrite(input, WriteOpInsert, tableName, schema)
}

func (b *builder) NamedDelete(input Rel, tableName []string, schema types.NamedStruct) (*NamedTableWriteRel, error) {
return b.NamedWriteRemap(input, WriteOpDelete, tableName, schema, nil)
return b.NamedWrite(input, WriteOpDelete, tableName, schema)
}

func (b *builder) NamedScanRemap(tableName []string, schema types.NamedStruct, remap []int32) (*NamedTableReadRel, error) {
Expand Down
11 changes: 10 additions & 1 deletion plan/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ func (rc *RelCommon) remap(initial types.RecordType) types.RecordType {
return *types.NewRecordTypeFromTypes(outTypes)
}

func (rc *RelCommon) OutputMapping() []int32 { return rc.mapping }
func (rc *RelCommon) OutputMapping() []int32 {
// Make a copy of the output mapping to prevent accidental modification.
mapCopy := make([]int32, len(rc.mapping))
copy(mapCopy, rc.mapping)
return mapCopy
}

func (rc *RelCommon) setMapping(mapping []int32) {
rc.mapping = mapping
}

func (rc *RelCommon) GetAdvancedExtension() *extensions.AdvancedExtension {
return rc.advExtension
Expand Down
17 changes: 17 additions & 0 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ type RewriteFunc func(expr.Expression) (expr.Expression, error)
// It contains the common functionality between the different relations
// and should be type switched to determine which relation type it actually
// is for evaluation.
//
// All the exported methods in this interface should be considered constant.
type Rel interface {
// Hint returns a set of changes to the operation which can influence
// efficiency and performance but should not impact correctness.
Expand All @@ -271,6 +273,21 @@ type Rel interface {
// result should be 3 columns consisting of the 5th, 2nd and 1st
// output columns from the underlying relation.
OutputMapping() []int32
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved

// Remap modifies the current relation by applying the provided
// mapping to the current relation. Typically used to remove any
// unneeded columns or provide them in a different order. If there
// already is a mapping on this relation, this provides mapping over
// the current mapping.
//
// If any column numbers specified are outside the currently available
// input range an error is returned and the mapping is left unchanged.
Remap(mapping ...int32) (Rel, error)

// setMapping sets the current mapping and is for internal use.
// It performs no checks. End users should call Remap() instead.
setMapping(mapping []int32)

// directOutputSchema returns the output record type of the underlying
// relation as a struct type. Mapping is not applied.
directOutputSchema() types.RecordType
Expand Down
Loading
Loading