Skip to content

Commit

Permalink
Import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrocharged committed Nov 16, 2023
1 parent 27ce113 commit 77fabe0
Show file tree
Hide file tree
Showing 40 changed files with 752 additions and 729 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci-check-repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ jobs:
- name: Check all
id: should_format
run: |
./postgres/parser/build.sh
GOFLAGS="-mod=readonly" go build ./...
go vet -mod=readonly ./...
./scripts/check_bats_fmt.sh
if ./scripts/check_fmt.sh ; then
Expand All @@ -36,6 +33,10 @@ jobs:
echo "Please run scripts/format_repo.sh to format this pull request."
exit 1;
fi
./postgres/parser/build.sh
GOFLAGS="-mod=readonly" go build ./...
go vet -mod=readonly ./...
env:
BRANCH_NAME: ${{ github.head_ref }}
CHANGE_TARGET: ${{ github.base_ref }}
2 changes: 1 addition & 1 deletion postgres/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/dolthub/doltgresql/utils"
)

//TODO: determine how to handle messages that are larger than the buffer
// TODO: determine how to handle messages that are larger than the buffer
const bufferSize = 2048

// connBuffers maintains a pool of buffers, reusable between connections.
Expand Down
31 changes: 16 additions & 15 deletions postgres/parser/encoding/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ func decodeLargeNumber(
// EncodeNonsortingDecimal returns the resulting byte slice with the
// encoded decimal appended to b. The encoding is limited compared to
// standard encodings in this package in that
// - It will not sort lexicographically
// - It does not encode its length or terminate itself, so decoding
// functions must be provided the exact encoded bytes
// - It will not sort lexicographically
// - It does not encode its length or terminate itself, so decoding
// functions must be provided the exact encoded bytes
//
// The encoding assumes that any number can be written as ±0.xyz... * 10^exp,
// where xyz is a digit string, x != 0, and the last decimal in xyz is also
Expand All @@ -525,21 +525,22 @@ func decodeLargeNumber(
// the digit string is added as a big-endian byte slice.
//
// All together, the encoding looks like:
// <marker><uvarint exponent><big-endian encoded big.Int>.
//
// <marker><uvarint exponent><big-endian encoded big.Int>.
//
// The markers are shared with the sorting decimal encoding as follows:
// decimalNaN -> decimalNaN
// decimalNegativeInfinity -> decimalNegativeInfinity
// decimalNegLarge -> decimalNegValPosExp
// decimalNegMedium -> decimalNegValZeroExp
// decimalNegSmall -> decimalNegValNegExp
// decimalZero -> decimalZero
// decimalPosSmall -> decimalPosValNegExp
// decimalPosMedium -> decimalPosValZeroExp
// decimalPosLarge -> decimalPosValPosExp
// decimalInfinity -> decimalInfinity
// decimalNaNDesc -> decimalNaNDesc
//
// decimalNaN -> decimalNaN
// decimalNegativeInfinity -> decimalNegativeInfinity
// decimalNegLarge -> decimalNegValPosExp
// decimalNegMedium -> decimalNegValZeroExp
// decimalNegSmall -> decimalNegValNegExp
// decimalZero -> decimalZero
// decimalPosSmall -> decimalPosValNegExp
// decimalPosMedium -> decimalPosValZeroExp
// decimalPosLarge -> decimalPosValPosExp
// decimalInfinity -> decimalInfinity
// decimalNaNDesc -> decimalNaNDesc
func EncodeNonsortingDecimal(b []byte, d *apd.Decimal) []byte {
neg := d.Negative
switch d.Form {
Expand Down
25 changes: 15 additions & 10 deletions postgres/parser/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ const (
// The gap between floatNaNDesc and bytesMarker was left for
// compatibility reasons.
bytesMarker byte = 0x12
bytesDescMarker byte = bytesMarker + 1
timeMarker byte = bytesDescMarker + 1
durationBigNegMarker byte = timeMarker + 1 // Only used for durations < MinInt64 nanos.
durationMarker byte = durationBigNegMarker + 1
durationBigPosMarker byte = durationMarker + 1 // Only used for durations > MaxInt64 nanos.
bytesDescMarker = bytesMarker + 1
timeMarker = bytesDescMarker + 1
durationBigNegMarker = timeMarker + 1 // Only used for durations < MinInt64 nanos.
durationMarker = durationBigNegMarker + 1
durationBigPosMarker = durationMarker + 1 // Only used for durations > MaxInt64 nanos.

decimalNaN = durationBigPosMarker + 1 // 24
decimalNegativeInfinity = decimalNaN + 1
Expand Down Expand Up @@ -569,6 +569,7 @@ func getBitArrayWordsLen(b []byte, term byte) (int, int, error) {

// Type represents the type of a value encoded by
// Encode{Null,NotNull,Varint,Uvarint,Float,Bytes}.
//
//go:generate stringer -type=Type
type Type int

Expand Down Expand Up @@ -912,12 +913,16 @@ func EncodeUntaggedDecimalValue(appendTo []byte, d *apd.Decimal) []byte {
// returned colID should be discarded.)
//
// Concretely:
// b := ...
// typeOffset, _, colID, typ, err := DecodeValueTag(b)
// _, _, _, typ, err := DecodeValueTag(b[typeOffset:])
//
// b := ...
// typeOffset, _, colID, typ, err := DecodeValueTag(b)
// _, _, _, typ, err := DecodeValueTag(b[typeOffset:])
//
// will return the same typ and err and
// DecodeFooValue(b)
// DecodeFooValue(b[typeOffset:])
//
// DecodeFooValue(b)
// DecodeFooValue(b[typeOffset:])
//
// will return the same thing. PeekValueLength works as expected with either of
// `b` or `b[typeOffset:]`.
func DecodeValueTag(b []byte) (typeOffset int, dataOffset int, colID uint32, typ Type, err error) {
Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/errorutil/unimplemented/unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewWithIssueDetailf(issue int, detail, format string, args ...interface{})
return unimplementedInternal(1 /*depth*/, issue, detail, true /*format*/, format, args...)
}

//TODO: remove issue int
// TODO: remove issue int
func unimplementedInternal(depth, issue int, detail string, format bool, msg string, args ...interface{}) error {
// Create the issue link.
link := errors.IssueLink{Detail: detail}
Expand Down
3 changes: 2 additions & 1 deletion postgres/parser/geo/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ func AdjustGeomTSRID(t geom.T, srid geopb.SRID) {
// IsLinearRingCCW returns whether a given linear ring is counter clock wise.
// See 2.07 of http://www.faqs.org/faqs/graphics/algorithms-faq/.
// "Find the lowest vertex (or, if there is more than one vertex with the same lowest coordinate,
// the rightmost of those vertices) and then take the cross product of the edges fore and aft of it."
//
// the rightmost of those vertices) and then take the cross product of the edges fore and aft of it."
func IsLinearRingCCW(linearRing *geom.LinearRing) bool {
smallestIdx := 0
smallest := linearRing.Coord(0)
Expand Down
4 changes: 2 additions & 2 deletions postgres/parser/geo/geopb/geopb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ message SpatialObject {
// Type is the type of the SpatialObject.
SpatialObjectType type = 1;
// EWKB is the EWKB representation of the spatial object.
bytes ewkb = 2 [(gogoproto.customname)="EWKB",(gogoproto.casttype)="EWKB"];
bytes ewkb = 2 [(gogoproto.customname) = "EWKB", (gogoproto.casttype) = "EWKB"];
// SRID is the denormalized SRID derived from the EWKB.
int32 srid = 3 [(gogoproto.customname)="SRID",(gogoproto.casttype)="SRID"];
int32 srid = 3 [(gogoproto.customname) = "SRID", (gogoproto.casttype) = "SRID"];
// ShapeType is denormalized ShapeType derived from the EWKB.
ShapeType shape_type = 4;
// BoundingBox is the bounding box of the SpatialObject.
Expand Down
12 changes: 6 additions & 6 deletions postgres/parser/ipaddr/ipaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ type Addr utils.Uint128

// IPAddr stores an IP address's family, IP, and host mask. This was chosen over
// Go's "net" IP, as that struct doesn't work well for what we need to do.
// - It discards information when parsing IPv4, forcing it to be IPv6, and then
// assuming IPv4-mapped IPv6 addresses are purely IPv4 (only for printing).
// This is solved by having a Family field.
// - ParseIP and ParseCIDR are very strict, whereas postgres' INET and CIDR
// have very relaxed constraints for parsing an IP.
// - Doing int64 operations is much more efficient than byte slice operations.
// - It discards information when parsing IPv4, forcing it to be IPv6, and then
// assuming IPv4-mapped IPv6 addresses are purely IPv4 (only for printing).
// This is solved by having a Family field.
// - ParseIP and ParseCIDR are very strict, whereas postgres' INET and CIDR
// have very relaxed constraints for parsing an IP.
// - Doing int64 operations is much more efficient than byte slice operations.
type IPAddr struct {
// Family denotes what type of IP the original IP was.
Family IPFamily
Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/lex/all_keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (
"text/template"
)

//TODO: investigate if this file may be safely deleted (maybe generation script too?)
// TODO: investigate if this file may be safely deleted (maybe generation script too?)
func main() {
blockRE := regexp.MustCompile(`^.*_keyword:`)
keywordRE := regexp.MustCompile(`[A-Z].*`)
Expand Down
7 changes: 5 additions & 2 deletions postgres/parser/pgdate/field_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,12 @@ func (fe *fieldExtract) MakeTimeWithoutTimezone() time.Time {

// stropTimezone converts the given time to a time that looks the same but is in
// UTC, e.g. from
// 2020-06-26 01:02:03 +0200 CEST
//
// 2020-06-26 01:02:03 +0200 CEST
//
// to
// 2020-06-27 01:02:03 +0000 UTC.
//
// 2020-06-27 01:02:03 +0000 UTC.
//
// Note that the two times don't represent the same time instant.
func stripTimezone(t time.Time) time.Time {
Expand Down
11 changes: 5 additions & 6 deletions postgres/parser/pgdate/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,12 @@ const (
// ParseDate converts a string into Date.
//
// Any specified timezone is inconsequential. Examples:
// - "now": parses to the local date (in the current timezone)
// - "2020-06-26 01:09:15.511971": parses to '2020-06-26'
// - "2020-06-26 01:09:15.511971-05": parses to '2020-06-26'
// - "now": parses to the local date (in the current timezone)
// - "2020-06-26 01:09:15.511971": parses to '2020-06-26'
// - "2020-06-26 01:09:15.511971-05": parses to '2020-06-26'
//
// The dependsOnContext return value indicates if we had to consult the given
// `now` value (either for the time or the local timezone).
//
func ParseDate(now time.Time, mode ParseMode, s string) (_ Date, dependsOnContext bool, _ error) {
fe := fieldExtract{
currentTime: now,
Expand Down Expand Up @@ -174,8 +173,8 @@ func ParseTime(
// location.
//
// Any specified timezone is inconsequential. Examples:
// - "now": parses to the local time of day (in the current timezone)
// - "01:09:15.511971" and "01:09:15.511971-05" parse to the same result
// - "now": parses to the local time of day (in the current timezone)
// - "01:09:15.511971" and "01:09:15.511971-05" parse to the same result
//
// The dependsOnContext return value indicates if we had to consult the given
// `now` value (either for the time or the local timezone).
Expand Down
8 changes: 4 additions & 4 deletions postgres/parser/pgerror/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ message Error {
string severity = 8;

message Source {
string file = 1;
int32 line = 2;
string function = 3;
string file = 1;
int32 line = 2;
string function = 3;
}
Source source = 5;

reserved 6,7;
reserved 6, 7;
};
6 changes: 3 additions & 3 deletions postgres/parser/pgerror/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import (
// the name implies, the details from the chain of causes is projected
// into a single struct. This is useful in at least two places:
//
// - to generate Error objects suitable for 19.1 nodes, which
// only recognize this type of payload.
// - to generate an error packet on pgwire.
// - to generate Error objects suitable for 19.1 nodes, which
// only recognize this type of payload.
// - to generate an error packet on pgwire.
//
// Additionally, this can be used in the remainder of the code
// base when an Error object is expected, until that code
Expand Down
9 changes: 6 additions & 3 deletions postgres/parser/pgerror/pgcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ func HasCandidateCode(err error) bool {
// UncategorizedError is used.
// An example implementation for computeDefaultCode is provided below.
//
// - after that, it combines the code computed already for the cause
// (inner) and the new code just computed at the current level (outer)
// as follows:
// - after that, it combines the code computed already for the cause
// (inner) and the new code just computed at the current level (outer)
// as follows:
//
// - if the outer code is uncategorized, the inner code is kept no
// matter what.
//
// - if the outer code has the special XX prefix, that is kept.
// (The "XX" prefix signals importance in the pg code hierarchy.)
//
// - if the inner code is not uncategorized, it is retained.
//
// - otherwise the outer code is retained.
//
// This function should not be used directly. It is only exported
Expand Down
6 changes: 3 additions & 3 deletions postgres/parser/pretty/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
//
// For example code with SQL to experiment further, refer to
// https://github.com/knz/prettier/
//
package pretty

import "fmt"
Expand Down Expand Up @@ -96,8 +95,9 @@ var Line Doc = line{}
//
// For example, text "hello" <> softbreak <> text "world"
// flattens to "helloworld" (one word) but splits across lines as:
// hello
// world
//
// hello
// world
//
// This is a common extension to Wadler's printer.
//
Expand Down
27 changes: 15 additions & 12 deletions postgres/parser/pretty/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ func JoinDoc(s Doc, d ...Doc) Doc {
// For example:
// aaaa
// <sep> bbb
// bbb
//
// bbb
//
// <sep> ccc
// ccc
//
// ccc
func JoinNestedRight(sep Doc, nested ...Doc) Doc {
switch len(nested) {
case 0:
Expand Down Expand Up @@ -229,16 +232,16 @@ const (
)

// Table defines a document that formats a list of pairs of items either:
// - as a 2-column table, with the two columns aligned for example:
// SELECT aaa
// bbb
// FROM ccc
// - as sections, for example:
// SELECT
// aaa
// bbb
// FROM
// ccc
// - as a 2-column table, with the two columns aligned for example:
// SELECT aaa
// bbb
// FROM ccc
// - as sections, for example:
// SELECT
// aaa
// bbb
// FROM
// ccc
//
// We restrict the left value in each list item to be a one-line string
// to make the width computation efficient.
Expand Down
7 changes: 3 additions & 4 deletions postgres/parser/sem/tree/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ func (node *AlterTableAddColumn) Format(ctx *FmtCtx) {
// stored in node.Cmds, into top-level commands to add those constraints.
// Currently, this only applies to checks. For example, the ADD COLUMN in
//
// ALTER TABLE t ADD COLUMN a INT CHECK (a < 1)
// ALTER TABLE t ADD COLUMN a INT CHECK (a < 1)
//
// is transformed into two commands, as in
//
// ALTER TABLE t ADD COLUMN a INT, ADD CONSTRAINT check_a CHECK (a < 1)
// ALTER TABLE t ADD COLUMN a INT, ADD CONSTRAINT check_a CHECK (a < 1)
//
// (with an auto-generated name).
//
Expand All @@ -137,8 +137,7 @@ func (node *AlterTableAddColumn) Format(ctx *FmtCtx) {
// constraints. For example, the following statement is accepted in
// CockroachDB and Postgres, but not necessarily other SQL databases:
//
// ALTER TABLE t ADD COLUMN a INT CHECK (a < b)
//
// ALTER TABLE t ADD COLUMN a INT CHECK (a < b)
func (node *AlterTable) HoistAddColumnConstraints() {
var normalizedCmds AlterTableCmds

Expand Down
16 changes: 9 additions & 7 deletions postgres/parser/sem/tree/casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ type castInfo struct {
//
// Each cast defines a volatility:
//
// - immutable casts yield the same result on the same arguments in whatever
// context they are evaluated.
// - immutable casts yield the same result on the same arguments in whatever
// context they are evaluated.
//
// - stable casts can yield a different result depending on the evaluation context:
// - session settings (e.g. bytes encoding format)
// - current timezone
// - current time (e.g. 'now'::string).
// - stable casts can yield a different result depending on the evaluation context:
//
// - session settings (e.g. bytes encoding format)
//
// - current timezone
//
// - current time (e.g. 'now'::string).
//
// TODO(radu): move the PerformCast code for each cast into functions defined
// within each cast.
//
var validCasts = []castInfo{
// Casts to BitFamily.
{from: types.UnknownFamily, to: types.BitFamily, volatility: VolatilityImmutable},
Expand Down
Loading

0 comments on commit 77fabe0

Please sign in to comment.