Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/dtablefunctions/dolt_diff.go (Go)

Code before:
	"github.com/dolthub/dolt/go/store/types"
)

const diffTableDefaultRowCount = 1000

var ErrInvalidNonLiteralArgument = errors.NewKind("Invalid argument to %s: %s – only literal values supported")
var ErrInvalidTableName = errors.NewKind("Invalid table name %s.")

var _ sql.TableFunction = (*DiffTableFunction)(nil)
var _ sql.ExecSourceRel = (*DiffTableFunction)(nil)
var _ sql.AuthorizationCheckerNode = (*DiffTableFunction)(nil)

type DiffTableFunction struct {
	tableDelta       diff.TableDelta
	fromCommitExpr   sql.Expression
	toCommitExpr     sql.Expression
	dotCommitExpr    sql.Expression
	tableNameExpr    sql.Expression
	database         sql.Database
	ctx              *sql.Context
	joiner           *rowconv.Joiner
	fromDate         *types.Timestamp
	toDate           *types.Timestamp
	sqlSch           sql.Schema
	showSkinny       bool
	includeCols      map[string]struct{}
	overriddenSchema schema.Schema
}

// NewInstance creates a new instance of TableFunction interface
func (dtf *DiffTableFunction) NewInstance(ctx *sql.Context, database sql.Database, expressions []sql.Expression) (sql.Node, error) {
	newInstance := &DiffTableFunction{
		ctx:      ctx,
		database: database,
	}

	node, err := newInstance.WithExpressions(expressions...)
	if err != nil {
		return nil, err
	}

	return node, nil
}

func (dtf *DiffTableFunction) DataLength(ctx *sql.Context) (uint64, error) {
	numBytesPerRow := schema.SchemaAvgLength(dtf.Schema())
	numRows, _, err := dtf.RowCount(ctx)
	if err != nil {
		return 0, err
	}
	return numBytesPerRow * numRows, nil

Review comment (performance):
I think for performance reasons, you'd want to add the new `overridenSchema` field to line 63, after `sqlSch`

Code after:
	"github.com/dolthub/dolt/go/store/types"
)

const diffTableDefaultRowCount = 1000

var ErrInvalidNonLiteralArgument = errors.NewKind("Invalid argument to %s: %s – only literal values supported")
var ErrInvalidTableName = errors.NewKind("Invalid table name %s.")

var _ sql.TableFunction = (*DiffTableFunction)(nil)
var _ sql.ExecSourceRel = (*DiffTableFunction)(nil)
var _ sql.AuthorizationCheckerNode = (*DiffTableFunction)(nil)

type DiffTableFunction struct {
	tableDelta       diff.TableDelta
	fromCommitExpr   sql.Expression
	toCommitExpr     sql.Expression
	dotCommitExpr    sql.Expression
	tableNameExpr    sql.Expression
	database         sql.Database
	ctx              *sql.Context
	joiner           *rowconv.Joiner
	fromDate         *types.Timestamp
	toDate           *types.Timestamp
	sqlSch           sql.Schema
	showSkinny       bool
	overriddenSchema schema.Schema
	includeCols      map[string]struct{}
}

// NewInstance creates a new instance of TableFunction interface
func (dtf *DiffTableFunction) NewInstance(ctx *sql.Context, database sql.Database, expressions []sql.Expression) (sql.Node, error) {
	newInstance := &DiffTableFunction{
		ctx:      ctx,
		database: database,
	}

	node, err := newInstance.WithExpressions(expressions...)
	if err != nil {
		return nil, err
	}

	return node, nil
}

func (dtf *DiffTableFunction) DataLength(ctx *sql.Context) (uint64, error) {
	numBytesPerRow := schema.SchemaAvgLength(dtf.Schema())
	numRows, _, err := dtf.RowCount(ctx)
	if err != nil {
		return 0, err
	}
	return numBytesPerRow * numRows, nil