Skip to content

Commit

Permalink
fix: host-type-count sql error (#19801)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
  • Loading branch information
swordqiu and Qiu Jian authored Mar 26, 2024
1 parent 2a7daa6 commit 4a3dcb4
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ require (
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
yunion.io/x/pkg v1.10.1-0.20240324150220-11d9be90fa6c
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.3-0.20240315065533-9ede1267a826
yunion.io/x/sqlchemy v1.1.3-0.20240326090913-96da8bf92408
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ yunion.io/x/pkg v1.10.1-0.20240324150220-11d9be90fa6c h1:c71AlEenWHcA6xJQN8dbtwX
yunion.io/x/pkg v1.10.1-0.20240324150220-11d9be90fa6c/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v1.1.3-0.20240315065533-9ede1267a826 h1:RLPGmjYWGXmxL1rq9a/bs3VSp2tAwtVMxsa/uXOV2xI=
yunion.io/x/sqlchemy v1.1.3-0.20240315065533-9ede1267a826/go.mod h1:5W8ghvJ4TNt/r2yDjjD3i4QsZgIiJX45dhRQBGWPHsQ=
yunion.io/x/sqlchemy v1.1.3-0.20240326090913-96da8bf92408 h1:TmkgsnVG/KsUfxaFxaYEhQs0o4nXc9fFFlqZv6mwZ/E=
yunion.io/x/sqlchemy v1.1.3-0.20240326090913-96da8bf92408/go.mod h1:5W8ghvJ4TNt/r2yDjjD3i4QsZgIiJX45dhRQBGWPHsQ=
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c h1:QuLab2kSRECZRxo4Lo2KcYn6XjQFDGaZ1+x0pYDVVwQ=
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
1 change: 1 addition & 0 deletions pkg/cloudcommon/db/standalone_anon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ func GetTagValueCountMap(
sqlchemy.NewFunction(
sqlchemy.NewCase().When(sqlchemy.IsNull(subq.Field("value")), sqlchemy.NewStringField(tagutils.NoValue)).Else(subq.Field("value")),
valueFieldName,
false,
),
)
groupBy = append(groupBy, q.Field(valueFieldName))
Expand Down
3 changes: 3 additions & 0 deletions pkg/compute/models/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -1554,13 +1554,15 @@ func (manager *SBucketManager) TotalCount(ctx context.Context, scope rbacscope.T
buckets.Field("object_cnt"),
).Else(sqlchemy.NewConstField(0)),
"object_cnt1",
false,
),
sqlchemy.NewFunction(
sqlchemy.NewCase().When(
sqlchemy.GE(buckets.Field("size_bytes"), 0),
buckets.Field("size_bytes"),
).Else(sqlchemy.NewConstField(0)),
"size_bytes1",
false,
),
sqlchemy.NewFunction(
sqlchemy.NewCase().When(
Expand All @@ -1569,6 +1571,7 @@ func (manager *SBucketManager) TotalCount(ctx context.Context, scope rbacscope.T
).Else(
buckets.Field("size_bytes")),
"size_bytes_limit",
false,
),
)
bucketsQ = manager.usageQ(bucketsQ, rangeObjs, providers, brands, cloudEnv)
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ func (hh *SHostManager) GetPropertyHostTypeCount(ctx context.Context, userCred m
hcso := sqlchemy.Equals(hosts.Field("host_type"), api.HOST_TYPE_HCSO)
cs.When(hcso, sqlchemy.COUNT("", sqlchemy.DISTINCT("", hosts.Field("external_id"))))
cs.Else(sqlchemy.COUNT("", hosts.Field("id")))
q := hosts.Query(hosts.Field("host_type"), sqlchemy.NewFunction(cs, "count"))
q := hosts.Query(hosts.Field("host_type"), sqlchemy.NewFunction(cs, "count", true))
return hh.getCount(ctx, userCred, q, query)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/models/networkaddresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (man *SNetworkAddressManager) ListItemFilter(ctx context.Context, q *sqlche
networks = networks.Join(wires, sqlchemy.Equals(wires.Field("id"), networks.Field("wire_id")))
networks = networks.Join(vpcs, sqlchemy.Equals(vpcs.Field("id"), wires.Field("vpc_id")))
networks = networks.AppendField(networks.Field("id"))
networks = networks.AppendField(sqlchemy.NewFunction(sqlchemy.NewCase().When(sqlchemy.IsNullOrEmpty(wires.Field("manager_id")), vpcs.Field("manager_id")).Else(wires.Field("manager_id")), "manager_id"))
networks = networks.AppendField(sqlchemy.NewFunction(sqlchemy.NewCase().When(sqlchemy.IsNullOrEmpty(wires.Field("manager_id")), vpcs.Field("manager_id")).Else(wires.Field("manager_id")), "manager_id", false))
subq := networks.SubQuery().Query()
subq = subq.AppendField(subq.Field("id"))
return subq
Expand Down
4 changes: 4 additions & 0 deletions pkg/keystone/models/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,27 +648,31 @@ func (manager *SAssignmentManager) queryAll(
sqlchemy.Equals(assigments.Field("type"), sqlchemy.NewStringField(api.AssignmentUserDomain)),
), assigments.Field("actor_id")).Else(sqlchemy.NewStringField("")),
"user_id",
false,
),
sqlchemy.NewFunction(
sqlchemy.NewCase().When(sqlchemy.OR(
sqlchemy.Equals(assigments.Field("type"), sqlchemy.NewStringField(api.AssignmentGroupProject)),
sqlchemy.Equals(assigments.Field("type"), sqlchemy.NewStringField(api.AssignmentGroupDomain)),
), assigments.Field("actor_id")).Else(sqlchemy.NewStringField("")),
"group_id",
false,
),
sqlchemy.NewFunction(
sqlchemy.NewCase().When(sqlchemy.OR(
sqlchemy.Equals(assigments.Field("type"), sqlchemy.NewStringField(api.AssignmentUserDomain)),
sqlchemy.Equals(assigments.Field("type"), sqlchemy.NewStringField(api.AssignmentGroupDomain)),
), assigments.Field("target_id")).Else(sqlchemy.NewStringField("")),
"domain_id",
false,
),
sqlchemy.NewFunction(
sqlchemy.NewCase().When(sqlchemy.OR(
sqlchemy.Equals(assigments.Field("type"), sqlchemy.NewStringField(api.AssignmentUserProject)),
sqlchemy.Equals(assigments.Field("type"), sqlchemy.NewStringField(api.AssignmentGroupProject)),
), assigments.Field("target_id")).Else(sqlchemy.NewStringField("")),
"project_id",
false,
),
assigments.Field("role_id"),
)
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ yunion.io/x/pkg/utils
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
## explicit; go 1.12
yunion.io/x/s3cli
# yunion.io/x/sqlchemy v1.1.3-0.20240315065533-9ede1267a826
# yunion.io/x/sqlchemy v1.1.3-0.20240326090913-96da8bf92408
## explicit; go 1.17
yunion.io/x/sqlchemy
yunion.io/x/sqlchemy/backends
Expand Down
3 changes: 2 additions & 1 deletion vendor/yunion.io/x/sqlchemy/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a3dcb4

Please sign in to comment.