Run pin-dependency.sh and update-vendor.sh.

This commit is contained in:
Kermit Alexander II
2022-08-22 16:59:14 +00:00
parent d581cc90ad
commit 4a703d6cbc
17 changed files with 192 additions and 166 deletions

View File

@@ -88,9 +88,9 @@ func (e astNode) ComputedSize() *SizeEstimate {
return e.derivedSize
}
var v uint64
switch ek := e.expr.ExprKind.(type) {
switch ek := e.expr.GetExprKind().(type) {
case *exprpb.Expr_ConstExpr:
switch ck := ek.ConstExpr.ConstantKind.(type) {
switch ck := ek.ConstExpr.GetConstantKind().(type) {
case *exprpb.Constant_StringValue:
v = uint64(len(ck.StringValue))
case *exprpb.Constant_BytesValue:
@@ -103,10 +103,10 @@ func (e astNode) ComputedSize() *SizeEstimate {
return nil
}
case *exprpb.Expr_ListExpr:
v = uint64(len(ek.ListExpr.Elements))
v = uint64(len(ek.ListExpr.GetElements()))
case *exprpb.Expr_StructExpr:
if ek.StructExpr.MessageName == "" {
v = uint64(len(ek.StructExpr.Entries))
if ek.StructExpr.GetMessageName() == "" {
v = uint64(len(ek.StructExpr.GetEntries()))
}
default:
return nil
@@ -297,7 +297,7 @@ func (c *coster) cost(e *exprpb.Expr) CostEstimate {
return CostEstimate{}
}
var cost CostEstimate
switch e.ExprKind.(type) {
switch e.GetExprKind().(type) {
case *exprpb.Expr_ConstExpr:
cost = constCost
case *exprpb.Expr_IdentExpr:
@@ -323,7 +323,7 @@ func (c *coster) costIdent(e *exprpb.Expr) CostEstimate {
// build and track the field path
if iterRange, ok := c.iterRanges.peek(identExpr.GetName()); ok {
switch c.checkedExpr.TypeMap[iterRange].TypeKind.(type) {
switch c.checkedExpr.TypeMap[iterRange].GetTypeKind().(type) {
case *exprpb.Type_ListType_:
c.addPath(e, append(c.exprPath[iterRange], "@items"))
case *exprpb.Type_MapType_:
@@ -350,7 +350,7 @@ func (c *coster) costSelect(e *exprpb.Expr) CostEstimate {
}
// build and track the field path
c.addPath(e, append(c.getPath(sel.GetOperand()), sel.Field))
c.addPath(e, append(c.getPath(sel.GetOperand()), sel.GetField()))
return sum
}
@@ -476,6 +476,15 @@ func (c *coster) sizeEstimate(t AstNode) SizeEstimate {
if l := c.estimator.EstimateSize(t); l != nil {
return *l
}
// return an estimate of 1 for return types of set
// lengths, since strings/bytes/more complex objects could be of
// variable length
if isScalar(t.Type()) {
// TODO: since the logic for size estimation is split between
// ComputedSize and isScalar, changing one will likely require changing
// the other, so they should be merged in the future if possible
return SizeEstimate{Min: 1, Max: 1}
}
return SizeEstimate{Min: 0, Max: math.MaxUint64}
}
@@ -599,3 +608,20 @@ func (c *coster) newAstNode(e *exprpb.Expr) *astNode {
}
return &astNode{path: path, t: c.getType(e), expr: e, derivedSize: derivedSize}
}
// isScalar returns true if the given type is known to be of a constant size at
// compile time. isScalar will return false for strings (they are variable-width)
// in addition to protobuf.Any and protobuf.Value (their size is not knowable at compile time).
func isScalar(t *exprpb.Type) bool {
switch kindOf(t) {
case kindPrimitive:
if t.GetPrimitive() != exprpb.Type_STRING && t.GetPrimitive() != exprpb.Type_BYTES {
return true
}
case kindWellKnown:
if t.GetWellKnown() == exprpb.Type_DURATION || t.GetWellKnown() == exprpb.Type_TIMESTAMP {
return true
}
}
return false
}