Skip to content

Commit

Permalink
Project import generated by Copybara. (#131)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 04596f78d9b9167d90c711866f90fa5cea2e7169

Co-authored-by: A. Googler <[email protected]>
  • Loading branch information
1 parent 53eaa40 commit e56329e
Show file tree
Hide file tree
Showing 4,656 changed files with 2,778,557 additions and 2,507 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ Notable limitations:
hints. However, index names generated in the emulator cannot be used in the
emulator or in production.

- Generated primary keys are not supported.

- The [Cloud Spanner PostgreSQL interface](
https://cloud.google.com/spanner/docs/postgresql-interface) is not supported.

Expand Down
28 changes: 14 additions & 14 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ http_archive(
build_file = "@//build/bazel:googleapis.BUILD",
patch_args = ["-p1"],
patches = ["//build/bazel:googleapis.patch"],
sha256 = "64080665f3c74998ff7d18f998713a9428c83f94400b0507d7469e8513fcaaa0",
strip_prefix = "googleapis-5096eae6a449e0ee66b68cfd2634cac97b682e88",
url = "https://github.com/googleapis/googleapis/archive/5096eae6a449e0ee66b68cfd2634cac97b682e88.tar.gz",
sha256 = "42a09adf83c5d43abacb4fb07d9958e37ffe50e9835f5ff82ba8e02ddb149a59",
strip_prefix = "googleapis-eda81ef50cbc08ddf39e9e0689e116421581a234",
url = "https://github.com/googleapis/googleapis/archive/eda81ef50cbc08ddf39e9e0689e116421581a234.tar.gz",
)

load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
Expand Down Expand Up @@ -155,32 +155,32 @@ go_repository(
name = "com_github_golang_glog",
build_file_proto_mode = "disable_global",
importpath = "github.com/golang/glog",
sum = "h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=",
version = "v1.0.0",
sum = "h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE=",
version = "v1.1.0",
)

go_repository(
name = "org_golang_x_net",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/net",
sum = "h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=",
version = "v0.8.0",
sum = "h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=",
version = "v0.14.0",
)

go_repository(
name = "org_golang_x_sys",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/sys",
sum = "h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=",
version = "v0.6.0",
sum = "h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=",
version = "v0.11.0",
)

go_repository(
name = "org_golang_x_text",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/text",
sum = "h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=",
version = "v0.8.0",
sum = "h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=",
version = "v0.12.0",
)

################################################################################
Expand Down Expand Up @@ -278,9 +278,9 @@ http_archive(
patches = ["//build/bazel:zetasql.patch"],
# Patches applied:
# - Give visibility to ZetaSQL's base library to reuse some utilities
sha256 = "02d2ae94c7ed597ae40930635d55f2090094ea8bf02dfcdc77c6b6d22ace9b8b",
strip_prefix = "zetasql-5133c6e373a3f67f7f40b0619a2913c3fcab8171",
url = "https://github.com/google/zetasql/archive/5133c6e373a3f67f7f40b0619a2913c3fcab8171.tar.gz",
sha256 = "2ba3436859e15109d4909fa99e143eca4141d54143eddd97a2f804baba76506c",
strip_prefix = "zetasql-0b082e844376e9485fef4f285f1bd34d5f3af6c4",
url = "https://github.com/google/zetasql/archive/0b082e844376e9485fef4f285f1bd34d5f3af6c4.tar.gz",
)

http_archive(
Expand Down
2 changes: 1 addition & 1 deletion backend/actions/change_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ absl::StatusOr<zetasql::Value> GetPartitionToken(
active_partition_tokens.push_back(itr->ColumnValue(0).string_value());
}
}
ZETASQL_RET_CHECK(!active_partition_tokens.empty());
std::sort(active_partition_tokens.begin(), active_partition_tokens.end());
ZETASQL_RET_CHECK(!active_partition_tokens.empty());
return zetasql::Value::String(active_partition_tokens[0]);
}
} // namespace
Expand Down
64 changes: 64 additions & 0 deletions backend/actions/change_stream_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ TEST_F(ChangeStreamTest, AddOneInsertOpAndCheckResultWriteOpContent) {
change_stream_->change_stream_partition_table()->FindColumn("end_time"));
const std::vector<zetasql::Value> values = {
zetasql::Value::String("11111"), zetasql::Value::NullTimestamp()};
// Insert 1st partition
ZETASQL_EXPECT_OK(store()->Insert(change_stream_->change_stream_partition_table(),
Key({String("11111")}), columns, values));
// Insert 2nd partition
const std::vector<zetasql::Value> values2 = {
zetasql::Value::String("22222"), zetasql::Value::NullTimestamp()};
ZETASQL_EXPECT_OK(store()->Insert(change_stream_->change_stream_partition_table(),
Key({String("22222")}), columns, values2));
// Insert base table entry.
ZETASQL_EXPECT_OK(effector_->Effect(
ctx(), Insert(table_, Key({Int64(1)}), base_columns_,
Expand Down Expand Up @@ -217,6 +223,64 @@ TEST_F(ChangeStreamTest, AddOneInsertOpAndCheckResultWriteOpContent) {
ASSERT_EQ(operation->values[13], zetasql::Value(Bool(false)));
}

TEST_F(ChangeStreamTest, AddTwoInsertForDiffSetCols) {
// Populate partition table with the initial partition token
std::vector<const Column*> columns;
columns.push_back(change_stream2_->change_stream_partition_table()
->FindKeyColumn("partition_token")
->column());
columns.push_back(
change_stream2_->change_stream_partition_table()->FindColumn("end_time"));
const std::vector<zetasql::Value> values = {
zetasql::Value::String("11111"), zetasql::Value::NullTimestamp()};
// Insert 1st partition
ZETASQL_EXPECT_OK(store()->Insert(change_stream2_->change_stream_partition_table(),
Key({String("11111")}), columns, values));
// Insert 1st base table entry. base_columns1 only contains the first two
// columns of TestTable2.
std::vector<const Column*> base_columns1 = {
table2_->FindColumn("int64_col"), table2_->FindColumn("string_col")};
ZETASQL_EXPECT_OK(
effector2_->Effect(ctx(), Insert(table2_, Key({Int64(1)}), base_columns1,
{Int64(1), String("value")})));
// Insert 2nd base table entry. base_columns2_ contains all columns of
// TestTable2.
ZETASQL_EXPECT_OK(effector2_->Effect(
ctx(), Insert(table2_, Key({Int64(2)}), base_columns2_,
{Int64(2), String("value"), String("value2")})));
ctx()->change_stream_effects()->BuildMutation();
// Verify change stream entry is added to the transaction buffer.
ASSERT_EQ(change_stream_effects_buffer()->GetWriteOps().size(), 1);
}

TEST_F(ChangeStreamTest, AddTwoInsertForDiffSetNonKeyTrackedCols) {
// Populate partition table with the initial partition token
std::vector<const Column*> columns;
columns.push_back(change_stream2_->change_stream_partition_table()
->FindKeyColumn("partition_token")
->column());
columns.push_back(
change_stream2_->change_stream_partition_table()->FindColumn("end_time"));
const std::vector<zetasql::Value> values = {
zetasql::Value::String("11111"), zetasql::Value::NullTimestamp()};
// Insert 1st partition
ZETASQL_EXPECT_OK(store()->Insert(change_stream2_->change_stream_partition_table(),
Key({String("11111")}), columns, values));
// Insert 1st base table entry.
std::vector<const Column*> base_columns1 = {table2_->FindColumn("int64_col")};
ZETASQL_EXPECT_OK(effector2_->Effect(
ctx(), Insert(table2_, Key({Int64(1)}), base_columns1, {Int64(1)})));
// Insert 2nd base table entry
std::vector<const Column*> base_columns2 = {
table2_->FindColumn("int64_col"), table2_->FindColumn("string_col")};
ZETASQL_EXPECT_OK(
effector2_->Effect(ctx(), Insert(table2_, Key({Int64(2)}), base_columns2,
{Int64(2), String("value")})));
ctx()->change_stream_effects()->BuildMutation();
// Verify change stream entry is added to the transaction buffer.
ASSERT_EQ(change_stream_effects_buffer()->GetWriteOps().size(), 2);
}

// Add operations with different mod_types to the buffer and check if distinct
// DataChangeRecords are generated once mod_type changed.
// Insert, Insert, Update, Update, Insert, Delete, Delete -> 4 WriteOps
Expand Down
2 changes: 1 addition & 1 deletion backend/actions/check_constraint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CheckConstraintVerifier::CheckConstraintVerifier(
zetasql::Catalog* function_catalog)
: check_constraint_(check_constraint) {
absl::Status s = PrepareExpression(check_constraint, function_catalog);
ZETASQL_DCHECK(s.ok()) << "Failed to initialize CheckConstraintVerifier: " << s;
ABSL_DCHECK(s.ok()) << "Failed to initialize CheckConstraintVerifier: " << s;
}

absl::Status CheckConstraintVerifier::VerifyInsertUpdateOp(
Expand Down
2 changes: 1 addition & 1 deletion backend/actions/generated_column.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ GeneratedColumnEffector::GeneratedColumnEffector(
const Table* table, zetasql::Catalog* function_catalog, bool for_keys)
: table_(table), for_keys_(for_keys) {
absl::Status s = Initialize(function_catalog);
ZETASQL_DCHECK(s.ok()) << "Failed to initialize GeneratedColumnEffector: " << s;
ABSL_DCHECK(s.ok()) << "Failed to initialize GeneratedColumnEffector: " << s;
}

absl::Status GeneratedColumnEffector::Initialize(
Expand Down
3 changes: 1 addition & 2 deletions backend/common/indexing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ absl::StatusOr<Key> ComputeIndexKey(const Row& base_row, const Index* index) {
for (const auto& key_column : index->index_data_table()->primary_key()) {
key.AddColumn(
GetColumnValueOrNull(base_row, key_column->column()->source_column()),
key_column->is_descending()
);
key_column->is_descending(), key_column->is_nulls_last());
}
ZETASQL_RETURN_IF_ERROR(ValidateKeySizeForIndex(index, key));
return key;
Expand Down
1 change: 1 addition & 0 deletions backend/database/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cc_library(
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:variant",
"@com_google_googleapis//google/spanner/admin/database/v1:database_cc_proto",
"@com_google_zetasql//zetasql/public:type",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void ChangeStreamPartitionChurner::PeriodicChurnPartitions(
absl::GetFlag(FLAGS_change_stream_churn_thread_retry_sleep_interval) +
absl::Milliseconds(delay));
if (!s.ok() && !absl::IsAborted(s)) {
ZETASQL_LOG(ERROR) << "Failed to churn change stream " << change_stream_name
ABSL_LOG(ERROR) << "Failed to churn change stream " << change_stream_name
<< " with status: " << s;
}
} while (!s.ok());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ChangeStreamPartitionChurner {
~ChurningThread() {
{
absl::MutexLock l(&mu);
ZETASQL_LOG(ERROR) << "Stopping ChurningThread ";
ABSL_LOG(ERROR) << "Stopping ChurningThread ";
stop_thread = true;
}
// Join the thread.
Expand Down
11 changes: 11 additions & 0 deletions backend/database/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <thread> // NOLINT
#include <utility>

#include "google/spanner/admin/database/v1/common.pb.h"
#include "absl/functional/bind_front.h"
#include "absl/memory/memory.h"
#include "absl/status/statusor.h"
Expand All @@ -31,6 +32,7 @@
#include "backend/database/change_stream/change_stream_partition_churner.h"
#include "backend/locking/manager.h"
#include "backend/query/query_engine.h"
#include "backend/schema/catalog/schema.h"
#include "backend/schema/catalog/versioned_catalog.h"
#include "backend/schema/updater/schema_updater.h"
#include "backend/schema/updater/scoped_schema_change_lock.h"
Expand Down Expand Up @@ -58,9 +60,18 @@ absl::StatusOr<std::unique_ptr<Database>> Database::Create(
database->query_engine_ =
std::make_unique<QueryEngine>(database->type_factory_.get());
database->action_manager_ = std::make_unique<ActionManager>();
database->dialect_ = schema_change_operation.database_dialect;

if (schema_change_operation.statements.empty()) {
if (database->dialect_ == database_api::DatabaseDialect::POSTGRESQL) {
// Create an empty schema with the dialect set.
database->versioned_catalog_ = std::make_unique<VersionedCatalog>(
std::make_unique<const Schema>(SchemaGraph::CreateEmpty()
,
database->dialect_));
} else {
database->versioned_catalog_ = std::make_unique<VersionedCatalog>();
}
} else {
SchemaUpdater updater;
ZETASQL_ASSIGN_OR_RETURN(
Expand Down
9 changes: 9 additions & 0 deletions backend/database/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string>
#include <vector>

#include "google/spanner/admin/database/v1/common.pb.h"
#include "zetasql/public/type.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
Expand All @@ -47,6 +48,8 @@ namespace spanner {
namespace emulator {
namespace backend {

namespace database_api = ::google::spanner::admin::database::v1;

// Database represents a database in the emulator backend.
//
// Database largely ties together various subsystems - transactions, locking,
Expand Down Expand Up @@ -108,6 +111,9 @@ class Database {
// Used to execute queries against the database.
QueryEngine* query_engine() { return query_engine_.get(); }

// Returns the database dialect.
database_api::DatabaseDialect dialect() { return dialect_; }

ChangeStreamPartitionChurner* get_change_stream_partition_churner() {
return change_stream_partition_churner_.get();
}
Expand Down Expand Up @@ -153,6 +159,9 @@ class Database {
// Maintains an action registry per schema.
std::unique_ptr<ActionManager> action_manager_;

// The database dialect.
database_api::DatabaseDialect dialect_;

std::unique_ptr<ChangeStreamPartitionChurner>
change_stream_partition_churner_;
};
Expand Down
66 changes: 66 additions & 0 deletions backend/database/database_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class DatabaseTest : public ::testing::Test {
TEST_F(DatabaseTest, CreateSuccessful) {
ZETASQL_ASSERT_OK_AND_ASSIGN(std::unique_ptr<Database> database,
Database::Create(&clock_, SchemaChangeOperation{}));
// Verifies that by default, a ZetaSQL database is created.
EXPECT_EQ(database->dialect(),
database_api::DatabaseDialect::GOOGLE_STANDARD_SQL);

std::vector<std::string> create_statements = {R"(
CREATE TABLE T(
Expand All @@ -75,6 +78,69 @@ TEST_F(DatabaseTest, CreateSuccessful) {
database,
Database::Create(&clock_,
SchemaChangeOperation{.statements = create_statements}));
// Verifies that by default, a ZetaSQL database is created.
EXPECT_EQ(database->dialect(),
database_api::DatabaseDialect::GOOGLE_STANDARD_SQL);
}

TEST_F(DatabaseTest, CreateWithGSQLDialectSuccessful) {
ZETASQL_ASSERT_OK_AND_ASSIGN(
std::unique_ptr<Database> database,
Database::Create(
&clock_,
SchemaChangeOperation{
.database_dialect =
database_api::DatabaseDialect::GOOGLE_STANDARD_SQL}));
EXPECT_EQ(database->dialect(),
database_api::DatabaseDialect::GOOGLE_STANDARD_SQL);

std::vector<std::string> create_statements = {R"(
CREATE TABLE T(
k1 INT64,
k2 INT64,
) PRIMARY KEY(k1)
)",
R"(
CREATE INDEX I on T(k1))"};

ZETASQL_ASSERT_OK_AND_ASSIGN(
database,
Database::Create(
&clock_,
SchemaChangeOperation{
.statements = create_statements,
.database_dialect =
database_api::DatabaseDialect::GOOGLE_STANDARD_SQL}));
EXPECT_EQ(database->dialect(),
database_api::DatabaseDialect::GOOGLE_STANDARD_SQL);
}

TEST_F(DatabaseTest, CreateWithPostgresDialectSuccessful) {
ZETASQL_ASSERT_OK_AND_ASSIGN(
std::unique_ptr<Database> database,
Database::Create(
&clock_,
SchemaChangeOperation{
.database_dialect = database_api::DatabaseDialect::POSTGRESQL}));
EXPECT_EQ(database->dialect(), database_api::DatabaseDialect::POSTGRESQL);

std::vector<std::string> create_statements = {R"(
CREATE TABLE T(
k1 bigint primary key,
k2 bigint
)
)",
R"(
CREATE INDEX I on T(k1))"};

ZETASQL_ASSERT_OK_AND_ASSIGN(
database,
Database::Create(
&clock_,
SchemaChangeOperation{
.statements = create_statements,
.database_dialect = database_api::DatabaseDialect::POSTGRESQL}));
EXPECT_EQ(database->dialect(), database_api::DatabaseDialect::POSTGRESQL);
}

TEST_F(DatabaseTest, UpdateSchemaSuccessful) {
Expand Down
Loading

0 comments on commit e56329e

Please sign in to comment.