forked from maddyblue/sqlfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_data.go
executable file
·87 lines (77 loc) · 2.5 KB
/
session_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package sessiondatapb
import (
"fmt"
"strings"
//"github.com/labulakalia/sqlfmt/cockroach/pkg/security"
)
// GetFloatPrec computes a precision suitable for a call to
// strconv.FormatFloat() or for use with '%.*g' in a printf-like
// function.
func (c DataConversionConfig) GetFloatPrec() int {
// The user-settable parameter ExtraFloatDigits indicates the number
// of digits to be used to format the float value. PostgreSQL
// combines this with %g.
// The formula is <type>_DIG + extra_float_digits,
// where <type> is either FLT (float4) or DBL (float8).
// Also the value "3" in PostgreSQL is special and meant to mean
// "all the precision needed to reproduce the float exactly". The Go
// formatter uses the special value -1 for this and activates a
// separate path in the formatter. We compare >= 3 here
// just in case the value is not gated properly in the implementation
// of SET.
if c.ExtraFloatDigits >= 3 {
return -1
}
// CockroachDB only implements float8 at this time and Go does not
// expose DBL_DIG, so we use the standard literal constant for
// 64bit floats.
const StdDoubleDigits = 15
nDigits := StdDoubleDigits + c.ExtraFloatDigits
if nDigits < 1 {
// Ensure the value is clamped at 1: printf %g does not allow
// values lower than 1. PostgreSQL does this too.
nDigits = 1
}
return int(nDigits)
}
func (m VectorizeExecMode) String() string {
switch m {
case VectorizeOn, VectorizeUnset:
return "on"
case VectorizeExperimentalAlways:
return "experimental_always"
case VectorizeOff:
return "off"
default:
return fmt.Sprintf("invalid (%d)", m)
}
}
// VectorizeExecModeFromString converts a string into a VectorizeExecMode.
// False is returned if the conversion was unsuccessful.
func VectorizeExecModeFromString(val string) (VectorizeExecMode, bool) {
var m VectorizeExecMode
switch strings.ToUpper(val) {
case "ON":
m = VectorizeOn
case "EXPERIMENTAL_ALWAYS":
m = VectorizeExperimentalAlways
case "OFF":
m = VectorizeOff
default:
return 0, false
}
return m, true
}
// User retrieves the current user.
//func (s *SessionData) User() security.SQLUsername {
// return s.UserProto.Decode()
//}