You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by da...@apache.org on 2022/11/09 14:41:36 UTC
[beam] 01/01: Convert initialisms to all caps
This is an automated email from the ASF dual-hosted git repository.
damccorm pushed a commit to branch users/damccorm/goLintFixes
in repository https://gitbox.apache.org/repos/asf/beam.git
commit 03019613bdcaf0df931197209297ffa79798b12e
Author: Danny McCormick <da...@google.com>
AuthorDate: Wed Nov 9 09:41:21 2022 -0500
Convert initialisms to all caps
---
sdks/go/pkg/beam/io/filesystem/s3/s3.go | 16 +++----
sdks/go/pkg/beam/io/filesystem/s3/util.go | 8 ++--
sdks/go/pkg/beam/options/jobopts/options.go | 2 +-
sdks/go/pkg/beam/options/jobopts/options_test.go | 2 +-
sdks/go/pkg/beam/options/resource/hint.go | 34 +++++++-------
sdks/go/pkg/beam/options/resource/hint_test.go | 60 ++++++++++++------------
6 files changed, 62 insertions(+), 60 deletions(-)
diff --git a/sdks/go/pkg/beam/io/filesystem/s3/s3.go b/sdks/go/pkg/beam/io/filesystem/s3/s3.go
index 08dd5cd99d7..20c07eb8daa 100644
--- a/sdks/go/pkg/beam/io/filesystem/s3/s3.go
+++ b/sdks/go/pkg/beam/io/filesystem/s3/s3.go
@@ -54,7 +54,7 @@ func (f *fs) Close() error {
// List returns a slice of the files in the filesystem that match the glob pattern.
func (f *fs) List(ctx context.Context, glob string) ([]string, error) {
- bucket, keyPattern, err := parseUri(glob)
+ bucket, keyPattern, err := parseURI(glob)
if err != nil {
return nil, fmt.Errorf("error parsing S3 uri: %v", err)
}
@@ -66,7 +66,7 @@ func (f *fs) List(ctx context.Context, glob string) ([]string, error) {
uris := make([]string, len(keys))
for i, key := range keys {
- uris[i] = makeUri(bucket, key)
+ uris[i] = makeURI(bucket, key)
}
return uris, nil
@@ -111,7 +111,7 @@ func (f *fs) listObjectKeys(
// OpenRead returns a new io.ReadCloser to read contents from the file. The caller must call Close
// on the returned io.ReadCloser when done reading.
func (f *fs) OpenRead(ctx context.Context, filename string) (io.ReadCloser, error) {
- bucket, key, err := parseUri(filename)
+ bucket, key, err := parseURI(filename)
if err != nil {
return nil, fmt.Errorf("error parsing S3 uri %s: %v", filename, err)
}
@@ -131,7 +131,7 @@ func (f *fs) OpenRead(ctx context.Context, filename string) (io.ReadCloser, erro
// OpenWrite returns a new io.WriteCloser to write contents to the file. The caller must call Close
// on the returned io.WriteCloser when done writing.
func (f *fs) OpenWrite(ctx context.Context, filename string) (io.WriteCloser, error) {
- bucket, key, err := parseUri(filename)
+ bucket, key, err := parseURI(filename)
if err != nil {
return nil, fmt.Errorf("error parsing S3 uri %s: %v", filename, err)
}
@@ -141,7 +141,7 @@ func (f *fs) OpenWrite(ctx context.Context, filename string) (io.WriteCloser, er
// Size returns the size of the file.
func (f *fs) Size(ctx context.Context, filename string) (int64, error) {
- bucket, key, err := parseUri(filename)
+ bucket, key, err := parseURI(filename)
if err != nil {
return -1, fmt.Errorf("error parsing S3 uri %s: %v", filename, err)
}
@@ -160,7 +160,7 @@ func (f *fs) Size(ctx context.Context, filename string) (int64, error) {
// Remove removes the file from the filesystem.
func (f *fs) Remove(ctx context.Context, filename string) error {
- bucket, key, err := parseUri(filename)
+ bucket, key, err := parseURI(filename)
if err != nil {
return fmt.Errorf("error parsing S3 uri %s: %v", filename, err)
}
@@ -178,13 +178,13 @@ func (f *fs) Remove(ctx context.Context, filename string) error {
// Copy copies the file from the old path to the new path.
func (f *fs) Copy(ctx context.Context, oldpath, newpath string) error {
- sourceBucket, sourceKey, err := parseUri(oldpath)
+ sourceBucket, sourceKey, err := parseURI(oldpath)
if err != nil {
return fmt.Errorf("error parsing S3 source uri %s: %v", oldpath, err)
}
copySource := fmt.Sprintf("%s/%s", sourceBucket, sourceKey)
- destBucket, destKey, err := parseUri(newpath)
+ destBucket, destKey, err := parseURI(newpath)
if err != nil {
return fmt.Errorf("error parsing S3 destination uri %s: %v", newpath, err)
}
diff --git a/sdks/go/pkg/beam/io/filesystem/s3/util.go b/sdks/go/pkg/beam/io/filesystem/s3/util.go
index db076594dac..3a5fdcccf79 100644
--- a/sdks/go/pkg/beam/io/filesystem/s3/util.go
+++ b/sdks/go/pkg/beam/io/filesystem/s3/util.go
@@ -22,8 +22,8 @@ import (
"strings"
)
-// parseUri deconstructs the S3 uri in the format 's3://bucket/key' to (bucket, key)
-func parseUri(uri string) (string, string, error) {
+// parseURI deconstructs the S3 uri in the format 's3://bucket/key' to (bucket, key)
+func parseURI(uri string) (string, string, error) {
parsed, err := url.Parse(uri)
if err != nil {
return "", "", err
@@ -46,8 +46,8 @@ func parseUri(uri string) (string, string, error) {
return bucket, key, nil
}
-// makeUri constructs an S3 uri from the bucket and key to the format 's3://bucket/key'
-func makeUri(bucket string, key string) string {
+// makeURI constructs an S3 uri from the bucket and key to the format 's3://bucket/key'
+func makeURI(bucket string, key string) string {
return fmt.Sprintf("s3://%s/%s", bucket, key)
}
diff --git a/sdks/go/pkg/beam/options/jobopts/options.go b/sdks/go/pkg/beam/options/jobopts/options.go
index af5c3f8c847..399d0108137 100644
--- a/sdks/go/pkg/beam/options/jobopts/options.go
+++ b/sdks/go/pkg/beam/options/jobopts/options.go
@@ -192,7 +192,7 @@ func GetPipelineResourceHints() resource.Hints {
var h resource.Hint
switch name {
case "min_ram", "beam:resources:min_ram_bytes:v1":
- h = resource.ParseMinRam(val)
+ h = resource.ParseMinRAM(val)
case "accelerator", "beam:resources:accelerator:v1":
h = resource.Accelerator(val)
default:
diff --git a/sdks/go/pkg/beam/options/jobopts/options_test.go b/sdks/go/pkg/beam/options/jobopts/options_test.go
index e6b297741d1..15fdc7dfbb8 100644
--- a/sdks/go/pkg/beam/options/jobopts/options_test.go
+++ b/sdks/go/pkg/beam/options/jobopts/options_test.go
@@ -150,7 +150,7 @@ func TestGetPipelineResourceHints(t *testing.T) {
hints.Set("min_ram=1GB")
ResourceHints = hints
- want := resource.NewHints(resource.ParseMinRam("1GB"), resource.Accelerator("pedal_to_the_metal"), stringHint{
+ want := resource.NewHints(resource.ParseMinRAM("1GB"), resource.Accelerator("pedal_to_the_metal"), stringHint{
urn: "beam:resources:novel_execution:v1",
value: "jaguar",
})
diff --git a/sdks/go/pkg/beam/options/resource/hint.go b/sdks/go/pkg/beam/options/resource/hint.go
index 2db4df0969a..1538fe65def 100644
--- a/sdks/go/pkg/beam/options/resource/hint.go
+++ b/sdks/go/pkg/beam/options/resource/hint.go
@@ -78,6 +78,7 @@ func (hs Hints) Equal(other Hints) bool {
return true
}
+// Payloads retuns a map from all hint URNs to the serialized byte representation of their payloads.
func (hs Hints) Payloads() map[string][]byte {
p := map[string][]byte{}
for k, h := range hs.h {
@@ -96,6 +97,7 @@ func NewHints(hs ...Hint) Hints {
return hints
}
+// Hint contains all the information about a given resource hint.
type Hint interface {
// URN returns the name for this hint.
URN() string
@@ -105,55 +107,55 @@ type Hint interface {
MergeWithOuter(outer Hint) Hint
}
-// MinRamBytes hints that this scope should be put in a machine with at least this many bytes of memory.
+// MinRAMBytes hints that this scope should be put in a machine with at least this many bytes of memory.
//
// Hints are advisory only and runners may not respect them.
//
// See https://beam.apache.org/documentation/runtime/resource-hints/ for more information about
// resource hints.
-func MinRamBytes(v uint64) Hint {
- return minRamHint{value: int64(v)}
+func MinRAMBytes(v uint64) Hint {
+ return minRAMHint{value: int64(v)}
}
-// ParseMinRam converts various byte units, including MB, GB, MiB, and GiB into a hint.
-// An invalid byte size format will cause ParseMinRam to panic.
+// ParseMinRAM converts various byte units, including MB, GB, MiB, and GiB into a hint.
+// An invalid byte size format will cause ParseMinRAM to panic.
//
// Hints are advisory only and runners may not respect them.
//
// See https://beam.apache.org/documentation/runtime/resource-hints/ for more information about
// resource hints.
-func ParseMinRam(v string) Hint {
+func ParseMinRAM(v string) Hint {
b, err := humanize.ParseBytes(v)
if err != nil {
- panic(fmt.Sprintf("resource.ParseMinRam: unable to parse %q: %v", v, err))
+ panic(fmt.Sprintf("resource.ParseMinRAM: unable to parse %q: %v", v, err))
}
- return MinRamBytes(b)
+ return MinRAMBytes(b)
}
-type minRamHint struct {
+type minRAMHint struct {
value int64
}
-func (minRamHint) URN() string {
+func (minRAMHint) URN() string {
return "beam:resources:min_ram_bytes:v1"
}
-func (a minRamHint) Payload() []byte {
+func (h minRAMHint) Payload() []byte {
// Go strings are utf8, and if the string is ascii,
// byte conversion handles that directly.
- return []byte(strconv.FormatInt(a.value, 10))
+ return []byte(strconv.FormatInt(h.value, 10))
}
-// MergeWith an outer minRamHints by keeping the maximum of the two byte amounts.
-func (h minRamHint) MergeWithOuter(outer Hint) Hint {
+// MergeWith an outer minRAMHints by keeping the maximum of the two byte amounts.
+func (h minRAMHint) MergeWithOuter(outer Hint) Hint {
// Intentional runtime panic from type assertion to catch hint merge errors.
- if outer.(minRamHint).value > h.value {
+ if outer.(minRAMHint).value > h.value {
return outer
}
return h
}
-func (h minRamHint) String() string {
+func (h minRAMHint) String() string {
return fmt.Sprintf("min_ram=%v", humanize.Bytes(uint64(h.value)))
}
diff --git a/sdks/go/pkg/beam/options/resource/hint_test.go b/sdks/go/pkg/beam/options/resource/hint_test.go
index 786dfb68a54..cf24b47b6c9 100644
--- a/sdks/go/pkg/beam/options/resource/hint_test.go
+++ b/sdks/go/pkg/beam/options/resource/hint_test.go
@@ -43,9 +43,9 @@ func TestAcceleratorHint_Payload(t *testing.T) {
}
}
-func TestMinRamBytesHint_MergeWith(t *testing.T) {
- low := minRamHint{value: 2}
- high := minRamHint{value: 12e7}
+func TestMinRAMBytesHint_MergeWith(t *testing.T) {
+ low := minRAMHint{value: 2}
+ high := minRAMHint{value: 12e7}
if got, want := low.MergeWithOuter(high), high; got != want {
t.Errorf("%v.MergeWith(%v) = %v, want %v", low, high, got, want)
@@ -55,7 +55,7 @@ func TestMinRamBytesHint_MergeWith(t *testing.T) {
}
}
-func TestMinRamBytesHint_Payload(t *testing.T) {
+func TestMinRAMBytesHint_Payload(t *testing.T) {
tests := []struct {
value int64
payload string
@@ -71,14 +71,14 @@ func TestMinRamBytesHint_Payload(t *testing.T) {
}
for _, test := range tests {
- h := minRamHint{value: test.value}
+ h := minRAMHint{value: test.value}
if got, want := h.Payload(), []byte(test.payload); !bytes.Equal(got, want) {
t.Errorf("%v.Payload() = %v, want %v", h, got, want)
}
}
}
-func TestParseMinRamHint(t *testing.T) {
+func TestParseMinRAMHint(t *testing.T) {
tests := []struct {
value string
payload string
@@ -95,20 +95,20 @@ func TestParseMinRamHint(t *testing.T) {
}
for _, test := range tests {
- h := ParseMinRam(test.value)
+ h := ParseMinRAM(test.value)
if got, want := h.Payload(), []byte(test.payload); !bytes.Equal(got, want) {
t.Errorf("%v.Payload() = %v, want %v", h, string(got), string(want))
}
}
}
-func TestParseMinRamHint_panic(t *testing.T) {
+func TestParseMinRAMHint_panic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
- t.Error("want ParseMinRam to panic")
+ t.Error("want ParseMinRAM to panic")
}
}()
- ParseMinRam("a bad byte string")
+ ParseMinRAM("a bad byte string")
}
// We copy the URN from the proto for use as a constant rather than perform a direct look up
@@ -128,7 +128,7 @@ func TestStandardHintUrns(t *testing.T) {
h: Accelerator("type:foo;count:bar;optional_option"),
urn: getStandardURN(pipepb.StandardResourceHints_ACCELERATOR),
}, {
- h: MinRamBytes(2e9),
+ h: MinRAMBytes(2e9),
urn: getStandardURN(pipepb.StandardResourceHints_MIN_RAM_BYTES),
}}
for _, test := range tests {
@@ -154,33 +154,33 @@ func (h customHint) MergeWithOuter(outer Hint) Hint {
}
func TestHints_Equal(t *testing.T) {
- hs := NewHints(MinRamBytes(2e9), Accelerator("type:pants;count1;install-pajamas"))
+ hs := NewHints(MinRAMBytes(2e9), Accelerator("type:pants;count1;install-pajamas"))
if got, want := hs.Equal(hs), true; got != want {
t.Errorf("Self equal test: hs.Equal(hs) = %v, want %v", got, want)
}
- eq := NewHints(MinRamBytes(2e9), Accelerator("type:pants;count1;install-pajamas"))
+ eq := NewHints(MinRAMBytes(2e9), Accelerator("type:pants;count1;install-pajamas"))
if got, want := hs.Equal(eq), true; got != want {
t.Errorf("identical equal test: hs.Equal(eq) = %v, want %v", got, want)
}
- neqLenShort := NewHints(MinRamBytes(2e9))
+ neqLenShort := NewHints(MinRAMBytes(2e9))
if got, want := hs.Equal(neqLenShort), false; got != want {
t.Errorf("too short equal test: hs.Equal(neqLenShort) = %v, want %v", got, want)
}
ch := customHint{}
- neqLenLong := NewHints(MinRamBytes(2e9), Accelerator("type:pants;count1;install-pajamas"), ch)
+ neqLenLong := NewHints(MinRAMBytes(2e9), Accelerator("type:pants;count1;install-pajamas"), ch)
if got, want := hs.Equal(neqLenLong), false; got != want {
t.Errorf("too long equal test: hs.Equal(neqLenLong) = %v, want %v", got, want)
}
- neqSameHintTypes := NewHints(MinRamBytes(2e10), Accelerator("type:pants;count1;install-pajamas"))
+ neqSameHintTypes := NewHints(MinRAMBytes(2e10), Accelerator("type:pants;count1;install-pajamas"))
if got, want := hs.Equal(neqSameHintTypes), false; got != want {
t.Errorf("sameHintTypes equal test: hs.Equal(neqLenSameHintTypes) = %v, want %v", got, want)
}
- neqSameHintTypes2 := NewHints(MinRamBytes(2e9), Accelerator("type:pants;count1;install-pajama"))
+ neqSameHintTypes2 := NewHints(MinRAMBytes(2e9), Accelerator("type:pants;count1;install-pajama"))
if got, want := hs.Equal(neqSameHintTypes2), false; got != want {
t.Errorf("sameHintTypes2 equal test: hs.Equal(neqLenSameHintTypes2) = %v, want %v", got, want)
}
- neqDiffHintTypes2 := NewHints(MinRamBytes(2e9), ch)
+ neqDiffHintTypes2 := NewHints(MinRAMBytes(2e9), ch)
if got, want := hs.Equal(neqDiffHintTypes2), false; got != want {
t.Errorf("diffHintTypes equal test: hs.Equal(neqDiffHintTypes2) = %v, want %v", got, want)
}
@@ -188,15 +188,15 @@ func TestHints_Equal(t *testing.T) {
func TestHints_MergeWithOuter(t *testing.T) {
- lowRam, medRam, highRam := MinRamBytes(2e7), MinRamBytes(2e9), MinRamBytes(2e10)
+ lowRAM, medRAM, highRAM := MinRAMBytes(2e7), MinRAMBytes(2e9), MinRAMBytes(2e10)
pantsAcc := Accelerator("type:pants;count1;install-pajamas")
jeansAcc := Accelerator("type:jeans;count1;")
custom := customHint{}
- hsA := NewHints(medRam, pantsAcc)
- hsB := NewHints(highRam, jeansAcc)
- hsC := NewHints(lowRam, custom)
+ hsA := NewHints(medRAM, pantsAcc)
+ hsB := NewHints(highRAM, jeansAcc)
+ hsC := NewHints(lowRAM, custom)
tests := []struct {
inner, outer, want Hints
@@ -204,12 +204,12 @@ func TestHints_MergeWithOuter(t *testing.T) {
{hsA, hsA, hsA},
{hsB, hsB, hsB},
{hsC, hsC, hsC},
- {hsA, hsB, NewHints(highRam, pantsAcc)},
- {hsB, hsA, NewHints(highRam, jeansAcc)},
- {hsA, hsC, NewHints(medRam, pantsAcc, custom)},
- {hsC, hsA, NewHints(medRam, pantsAcc, custom)},
- {hsB, hsC, NewHints(highRam, jeansAcc, custom)},
- {hsC, hsB, NewHints(highRam, jeansAcc, custom)},
+ {hsA, hsB, NewHints(highRAM, pantsAcc)},
+ {hsB, hsA, NewHints(highRAM, jeansAcc)},
+ {hsA, hsC, NewHints(medRAM, pantsAcc, custom)},
+ {hsC, hsA, NewHints(medRAM, pantsAcc, custom)},
+ {hsB, hsC, NewHints(highRAM, jeansAcc, custom)},
+ {hsC, hsB, NewHints(highRAM, jeansAcc, custom)},
}
for i, test := range tests {
@@ -223,7 +223,7 @@ func TestHints_MergeWithOuter(t *testing.T) {
func TestHints_Payloads(t *testing.T) {
{
- hs := NewHints(MinRamBytes(2e9), Accelerator("type:jeans;count1;"))
+ hs := NewHints(MinRAMBytes(2e9), Accelerator("type:jeans;count1;"))
got := hs.Payloads()
want := map[string][]byte{
@@ -248,7 +248,7 @@ func TestHints_Payloads(t *testing.T) {
func TestHints_NilHints(t *testing.T) {
var hs1, hs2 Hints
- hs := NewHints(MinRamBytes(2e9), Accelerator("type:pants;count1;install-pajamas"))
+ hs := NewHints(MinRAMBytes(2e9), Accelerator("type:pants;count1;install-pajamas"))
if got, want := hs1.Equal(hs2), true; got != want {
t.Errorf("nils equal test: (nil).Equal(nil) = %v, want %v", got, want)