-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
53243: builtins: implement ST_IsPolygonCW/CCW and ST_ForcePolygonCW/CCW r=sumeerbhola a=otan Resolves #48956 Resolves #48957 Resolves #48935 Resolves #48936 Release note (sql change): implement the ST_IsPolygonCW, ST_IsPolygonCCW, ST_ForcePolygonCW and ST_ForcePolygonCCW builtins. Release justification: low risk, high benefit changes 53478: backupccl: prevent temporary tables from backupccl r=pbardea a=otan Filter out temporary tables from resolvable descriptors. Release justification: low risk, high benefit changes Resolves: #50902 Release note (sql change): Fix a bug where temporary tables may be included in `BACKUP` commands. 53496: builtins: implement ST_Points r=otan a=erikgrinaker Release note (sql change): Implement the geometry builtin `ST_Points`. Closes #49009. 53523: sql: allow INT to compare to OID r=jordanlewis a=rafiss An OID is just an INT, so they should be comparable. Postgres allows this, and certain drivers create queries that attempt to compare INTs to OIDs, so this improves compatibility. fixes #53143 Release justification: low-risk, high benefit change that improves compatibility with PGJDBC. Release note (sql change): A value of type OID can now be compared to a value of type INT. 53545: vendor: go get github.com/cockroachdb/datadriven@master r=knz a=tbg Picks up cockroachdb/datadriven#28. Release justification: testing Release note: None Co-authored-by: Oliver Tan <[email protected]> Co-authored-by: Erik Grinaker <[email protected]> Co-authored-by: Rafi Shamim <[email protected]> Co-authored-by: Tobias Grieger <[email protected]>
- Loading branch information
Showing
19 changed files
with
786 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Test that temporary tables do not show up in any backup. | ||
|
||
new-server name=s1 | ||
---- | ||
|
||
exec-sql | ||
SET experimental_enable_temp_tables=true; | ||
|
||
CREATE DATABASE d1; | ||
USE d1; | ||
CREATE TEMP TABLE temp_table (id int primary key); | ||
CREATE TABLE perm_table (id int primary key) | ||
---- | ||
|
||
query-sql | ||
SELECT table_name FROM [SHOW TABLES] ORDER BY table_name | ||
---- | ||
perm_table | ||
temp_table | ||
|
||
query-sql | ||
SELECT | ||
regexp_replace(schema_name, 'pg_temp.*', 'pg_temp') as name | ||
FROM [SHOW SCHEMAS] ORDER BY name | ||
---- | ||
crdb_internal | ||
information_schema | ||
pg_catalog | ||
pg_extension | ||
pg_temp | ||
public | ||
|
||
exec-sql | ||
BACKUP TABLE temp_table TO 'nodelocal://0/temp_table_backup' | ||
---- | ||
pq: table "temp_table" does not exist | ||
|
||
exec-sql | ||
BACKUP DATABASE d1 TO 'nodelocal://0/d1_backup/' | ||
---- | ||
|
||
exec-sql | ||
BACKUP d1.* TO 'nodelocal://0/d1_star_backup/' | ||
---- | ||
|
||
exec-sql | ||
USE defaultdb; | ||
DROP DATABASE d1; | ||
RESTORE DATABASE d1 FROM 'nodelocal://0/d1_backup/'; | ||
USE d1 | ||
---- | ||
|
||
query-sql | ||
SELECT | ||
regexp_replace(schema_name, 'pg_temp.*', 'pg_temp') AS name | ||
FROM [SHOW SCHEMAS] ORDER BY name | ||
---- | ||
crdb_internal | ||
information_schema | ||
pg_catalog | ||
pg_extension | ||
public | ||
|
||
query-sql | ||
SELECT table_name FROM [SHOW TABLES] ORDER BY table_name | ||
---- | ||
perm_table | ||
|
||
exec-sql | ||
USE defaultdb; | ||
DROP DATABASE d1; | ||
RESTORE DATABASE d1 FROM 'nodelocal://0/d1_star_backup/'; | ||
USE d1 | ||
---- | ||
|
||
query-sql | ||
SELECT | ||
regexp_replace(schema_name, 'pg_temp.*', 'pg_temp') AS name | ||
FROM [SHOW SCHEMAS] ORDER BY name | ||
---- | ||
crdb_internal | ||
information_schema | ||
pg_catalog | ||
pg_extension | ||
public | ||
|
||
query-sql | ||
USE d1; | ||
SELECT table_name FROM [SHOW TABLES] ORDER BY table_name | ||
---- | ||
perm_table |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// 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 geomfn | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/geo" | ||
"github.com/cockroachdb/errors" | ||
"github.com/twpayne/go-geom" | ||
) | ||
|
||
// Orientation defines an orientation of a shape. | ||
type Orientation int | ||
|
||
const ( | ||
// OrientationCW denotes a clockwise orientation. | ||
OrientationCW Orientation = iota | ||
// OrientationCCW denotes a counter-clockwise orientation | ||
OrientationCCW | ||
) | ||
|
||
// HasPolygonOrientation checks whether a given Geometry have polygons | ||
// that matches the given Orientation. | ||
// Non-Polygon objects | ||
func HasPolygonOrientation(g geo.Geometry, o Orientation) (bool, error) { | ||
t, err := g.AsGeomT() | ||
if err != nil { | ||
return false, err | ||
} | ||
return hasPolygonOrientation(t, o) | ||
} | ||
|
||
func hasPolygonOrientation(g geom.T, o Orientation) (bool, error) { | ||
switch g := g.(type) { | ||
case *geom.Polygon: | ||
for i := 0; i < g.NumLinearRings(); i++ { | ||
isCCW := geo.IsLinearRingCCW(g.LinearRing(i)) | ||
// Interior rings should be the reverse orientation of the exterior ring. | ||
if i > 0 { | ||
isCCW = !isCCW | ||
} | ||
switch o { | ||
case OrientationCW: | ||
if isCCW { | ||
return false, nil | ||
} | ||
case OrientationCCW: | ||
if !isCCW { | ||
return false, nil | ||
} | ||
default: | ||
return false, errors.Newf("unexpected orientation: %v", o) | ||
} | ||
} | ||
return true, nil | ||
case *geom.MultiPolygon: | ||
for i := 0; i < g.NumPolygons(); i++ { | ||
if ret, err := hasPolygonOrientation(g.Polygon(i), o); !ret || err != nil { | ||
return ret, err | ||
} | ||
} | ||
return true, nil | ||
case *geom.GeometryCollection: | ||
for i := 0; i < g.NumGeoms(); i++ { | ||
if ret, err := hasPolygonOrientation(g.Geom(i), o); !ret || err != nil { | ||
return ret, err | ||
} | ||
} | ||
return true, nil | ||
case *geom.Point, *geom.MultiPoint, *geom.LineString, *geom.MultiLineString: | ||
return true, nil | ||
default: | ||
return false, errors.Newf("unhandled geometry type: %T", g) | ||
} | ||
} | ||
|
||
// ForcePolygonOrientation forces orientations within polygons | ||
// to be oriented the prescribed way. | ||
func ForcePolygonOrientation(g geo.Geometry, o Orientation) (geo.Geometry, error) { | ||
t, err := g.AsGeomT() | ||
if err != nil { | ||
return geo.Geometry{}, err | ||
} | ||
|
||
if err := forcePolygonOrientation(t, o); err != nil { | ||
return geo.Geometry{}, err | ||
} | ||
return geo.MakeGeometryFromGeomT(t) | ||
} | ||
|
||
func forcePolygonOrientation(g geom.T, o Orientation) error { | ||
switch g := g.(type) { | ||
case *geom.Polygon: | ||
for i := 0; i < g.NumLinearRings(); i++ { | ||
isCCW := geo.IsLinearRingCCW(g.LinearRing(i)) | ||
// Interior rings should be the reverse orientation of the exterior ring. | ||
if i > 0 { | ||
isCCW = !isCCW | ||
} | ||
reverse := false | ||
switch o { | ||
case OrientationCW: | ||
if isCCW { | ||
reverse = true | ||
} | ||
case OrientationCCW: | ||
if !isCCW { | ||
reverse = true | ||
} | ||
default: | ||
return errors.Newf("unexpected orientation: %v", o) | ||
} | ||
|
||
if reverse { | ||
// Reverse coordinates from both ends. | ||
// Do this by swapping up to the middle of the array of elements, which guarantees | ||
// each end get swapped. This works for an odd number of elements as well as | ||
// the middle element ends swapping with itself, which is ok. | ||
coords := g.LinearRing(i).FlatCoords() | ||
for cIdx := 0; cIdx < len(coords)/2; cIdx += g.Stride() { | ||
for sIdx := 0; sIdx < g.Stride(); sIdx++ { | ||
coords[cIdx+sIdx], coords[len(coords)-cIdx-g.Stride()+sIdx] = coords[len(coords)-cIdx-g.Stride()+sIdx], coords[cIdx+sIdx] | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
case *geom.MultiPolygon: | ||
for i := 0; i < g.NumPolygons(); i++ { | ||
if err := forcePolygonOrientation(g.Polygon(i), o); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
case *geom.GeometryCollection: | ||
for i := 0; i < g.NumGeoms(); i++ { | ||
if err := forcePolygonOrientation(g.Geom(i), o); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
case *geom.Point, *geom.MultiPoint, *geom.LineString, *geom.MultiLineString: | ||
return nil | ||
default: | ||
return errors.Newf("unhandled geometry type: %T", g) | ||
} | ||
} |
Oops, something went wrong.