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

[SNOW-1669514] Honor the Valuer/Stringer methods to resolve #1209 #1211

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

ChronosMasterOfAllTime
Copy link

@ChronosMasterOfAllTime ChronosMasterOfAllTime commented Sep 19, 2024

Description

SNOW-1669514 - Solve the issue with UUID getting double quoted due to new array function #1209

This adds the ability to check the valuer/stringer interfaces exists

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary

Proof test fails.

export SKIP_SETUP=true && go test -run ^TestValueToString$ github.com/snowflakedb/gosnowflake
--- FAIL: TestValueToString (0.00s)
    --- FAIL: TestValueToString/UUID_-_should_return_string (0.00s)
        assert_test.go:103: expected "json" to be empty, but was not. . Thrown from gosnowflake/converter_test.go:290 +0xd4
            testing.tRunner(0xc0000bf520, 0x100e3a478)
        assert_test.go:103: expected ""1414b0f8-e56a-4e14-995b-774d87ea9d73"" to be equal to "1414b0f8-e56a-4e14-995b-774d87ea9d73" but was not. . Thrown from gosnowflake/converter_test.go:291 +0x197
            testing.tRunner(0xc0000bf520, 0x100e3a478)

@ChronosMasterOfAllTime ChronosMasterOfAllTime changed the title Try to recreate the issue with UUID to solve #1209 WIP: Try to recreate the issue with UUID to solve #1209 Sep 19, 2024
@ChronosMasterOfAllTime ChronosMasterOfAllTime changed the title WIP: Try to recreate the issue with UUID to solve #1209 Recreate the issue with UUID to solve #1209 Sep 19, 2024
converter.go Outdated Show resolved Hide resolved
@ChronosMasterOfAllTime ChronosMasterOfAllTime changed the title Recreate the issue with UUID to solve #1209 Honor the Valuer/Stringer methods to resolve #1209 Sep 20, 2024
return bindingValue{}, nil
} else if stringer, ok := v1.Interface().(fmt.Stringer); ok { // alternate approach; check for stringer method. Guarantees it's String() and returns string
value := stringer.String()
return bindingValue{&value, "", nil}, nil
}
res, err := json.Marshal(v)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this, the bindingValue is set to "json". Should that be the case, or should it be string? Since it is already Marshaled, why set it to json again? That will cause it to be marshaled a second time. It feels like it should not marshal here if it also sets the binding value to json.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be clear This is in reference to the code on Lines 406-409; the added code will not return the "json" string as it's already been transformed

// if the output value is a valid string, return that
if strVal, ok := value.(string); ok {
return bindingValue{&strVal, "", nil}, nil
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this here as a suggestion; did we want to let a marshaler handle the driver's value if not a string by default?

EDIT: The below suggestion would break sql.NullTime. Tests pass if we dont use the below suggestion. This is unless we don't want the expectation to be Epoch Time for this case?

@sfc-gh-dszmolka ^^

Suggested change
}
} else if marshaled, err := json.Marshal(value); err == nil {
value := string(marshaled)
return bindingValue{&value, jsonFormatStr, nil}, nil
}

@@ -28,6 +28,7 @@ import (

const format = "2006-01-02 15:04:05.999999999"
const numberDefaultPrecision = 38
const jsonFormatStr = "json"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfc-gh-dszmolka can you please explain how the format string is being used by the execBindQuery struct, or what is the purpose of this field?

@ChronosMasterOfAllTime ChronosMasterOfAllTime changed the title Honor the Valuer/Stringer methods to resolve #1209 [SNOW-1669514] Honor the Valuer/Stringer methods to resolve #1209 Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants