Skip to content

Commit

Permalink
License header and linter warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 21, 2024
1 parent 57b5bfa commit a39acc3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
14 changes: 7 additions & 7 deletions go/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ func run(out io.Writer, cfg Config) error {
if err != nil {
return err
}
out.Write(b)
return nil
_, err = out.Write(b)
return err
}

type TableInfo struct {
Name string
Rows int
}

type SchemaInfo struct {
type Info struct {
Tables []TableInfo
}

func Get(cfg Config) (*SchemaInfo, error) {
func Get(cfg Config) (*Info, error) {
vtParams := &mysql.ConnParams{
Host: cfg.VTParams.Host,
Port: cfg.VTParams.Port,
Expand Down Expand Up @@ -84,18 +84,18 @@ func Get(cfg Config) (*SchemaInfo, error) {
Rows: int(tableRows),
})
}
schemaInfo := &SchemaInfo{
schemaInfo := &Info{
Tables: tables,
}
return schemaInfo, nil
}

func Load(fileName string) (*SchemaInfo, error) {
func Load(fileName string) (*Info, error) {
b, err := os.ReadFile(fileName)
if err != nil {
return nil, err
}
var si SchemaInfo
var si Info
err = json.Unmarshal(b, &si)
if err != nil {
return nil, err
Expand Down
20 changes: 18 additions & 2 deletions go/schema/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package schema

import (
Expand All @@ -11,7 +27,7 @@ func TestSchema(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, si)
require.NotEmpty(t, si.Tables)
require.Equal(t, 16, len(si.Tables))
require.Len(t, si.Tables, 16)
var tables []string
for _, table := range si.Tables {
tables = append(tables, table.Name)
Expand All @@ -26,7 +42,7 @@ func TestSchema(t *testing.T) {
case "film":
require.Equal(t, 1000, table.Rows)
default:
require.Greater(t, table.Rows, 0, "table %s has no rows", table.Name)
require.Positive(t, table.Rows, "table %s has no rows", table.Name)
}
}
}
7 changes: 3 additions & 4 deletions go/summarize/summarize-keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ import (
"strconv"
"time"

"github.com/vitessio/vt/go/schema"

"vitess.io/vitess/go/slice"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtgate/planbuilder/operators"

"github.com/vitessio/vt/go/keys"
"github.com/vitessio/vt/go/markdown"
"github.com/vitessio/vt/go/schema"
)

const HotQueryCount = 10
Expand Down Expand Up @@ -168,7 +167,7 @@ func printKeysSummary(out io.Writer, file readingSummary, now time.Time, hotMetr
md.Printf(msg, now.Format(time.DateTime), file.Name)
metricReader := getMetricForHotness(hotMetric)

var schemaInfo *schema.SchemaInfo
var schemaInfo *schema.Info
if schemaInfoPath != "" {
schemaInfo, err = schema.Load(schemaInfoPath)
if err != nil {
Expand Down Expand Up @@ -420,7 +419,7 @@ func makeKey(lhs, rhs operators.Column) graphKey {
return graphKey{rhs.Table, lhs.Table}
}

func summarizeKeysQueries(queries *keys.Output, metricReader getMetric, schemaInfo *schema.SchemaInfo) Summary {
func summarizeKeysQueries(queries *keys.Output, metricReader getMetric, schemaInfo *schema.Info) Summary {
tableSummaries := make(map[string]*TableSummary)
tableUsageWriteCounts := make(map[string]int)
tableUsageReadCounts := make(map[string]int)
Expand Down

0 comments on commit a39acc3

Please sign in to comment.