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

improve UX for metadata queries #4377

Merged
merged 1 commit into from
Feb 14, 2023
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
19 changes: 19 additions & 0 deletions compiler/ast/dag/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ type (
}
)

var LakeMetas = map[string]struct{}{
"branches": {},
"index_rules": {},
"pools": {},
}

var PoolMetas = map[string]struct{}{
"branches": {},
}

var CommitMetas = map[string]struct{}{
"indexes": {},
"log": {},
"objects": {},
"partitions": {},
"rawlog": {},
"vectors": {},
}

type Source interface {
Source()
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ func (o *Optimizer) getLayout(s dag.Source, parent order.Layout) (order.Layout,
return s.Layout, nil
case *dag.HTTP:
return s.Layout, nil
case *dag.Pool, *dag.LakeMeta, *dag.PoolMeta, *dag.CommitMeta:
case *dag.Pool:
return o.source.Layout(o.ctx, s), nil
case *dag.LakeMeta, *dag.PoolMeta, *dag.CommitMeta:
return order.Nil, nil
case *dag.Pass:
return parent, nil
case *kernel.Reader:
Expand Down
35 changes: 23 additions & 12 deletions compiler/semantic/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ func semPoolWithName(ctx context.Context, scope *Scope, p *ast.Pool, poolName st
commit = head.Branch
}
if poolName == "" {
if p.Spec.Meta == "" {
meta := p.Spec.Meta
if meta == "" {
return nil, errors.New("pool name missing")
}
if _, ok := dag.LakeMetas[meta]; !ok {
return nil, fmt.Errorf("unknown lake metadata type %q in from operator", meta)
}
return &dag.LakeMeta{
Kind: "LakeMeta",
Meta: p.Spec.Meta,
Expand All @@ -176,9 +180,7 @@ func semPoolWithName(ctx context.Context, scope *Scope, p *ast.Pool, poolName st
// If a name appears as an 0x bytes ksuid, convert it to the
// ksuid string form since the backend doesn't parse the 0x format.
poolID, err := lakeparse.ParseID(poolName)
if err == nil {
poolName = poolID.String()
} else {
if err != nil {
poolID, err = ds.PoolID(ctx, poolName)
if err != nil {
return nil, err
Expand All @@ -203,20 +205,29 @@ func semPoolWithName(ctx context.Context, scope *Scope, p *ast.Pool, poolName st
}
}
}
if p.Spec.Meta != "" {
if commit != "" {
if meta := p.Spec.Meta; meta != "" {
if _, ok := dag.CommitMetas[meta]; ok {
if commitID == ksuid.Nil {
commitID, err = ds.CommitObject(ctx, poolID, "main")
if err != nil {
return nil, err
}
}
return &dag.CommitMeta{
Kind: "CommitMeta",
Meta: p.Spec.Meta,
Meta: meta,
Pool: poolID,
Commit: commitID,
}, nil
}
return &dag.PoolMeta{
Kind: "PoolMeta",
Meta: p.Spec.Meta,
ID: poolID,
}, nil
if _, ok := dag.PoolMetas[meta]; ok {
return &dag.PoolMeta{
Kind: "PoolMeta",
Meta: meta,
ID: poolID,
}, nil
}
return nil, fmt.Errorf("unknown metadata type %q in from operator", meta)
}
if commitID == ksuid.Nil {
// This trick here allows us to default to the main branch when
Expand Down
2 changes: 1 addition & 1 deletion lake/ztests/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ script: |
zed query -Z 'from :pools | drop id | sort name | drop ts'
echo ===
zed query -Z 'from poolA@main:objects | cut nameof(this),meta'
zed query -Z 'from poolA@main:log | cut nameof(this) | drop ts'
zed query -Z 'from poolA:log | cut nameof(this) | drop ts'
echo ===
zed index create -q Rule field a
zed query -Z 'from :index_rules | nameof:=nameof(this) | drop ts,id'
Expand Down