mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-10 07:53:08 -06:00
Adding CreateDatabaseDDL option to the existing ops
This commit is contained in:
parent
9670d43ed9
commit
1894f5f148
@ -55,6 +55,8 @@ public class GCPSpannerOpMapper implements OpMapper<GCPSpannerBaseOp<?>> {
|
||||
logger.info(() -> "Using '" + typeAndTarget.enumId + "' op type for op template '" + op.getName() + "'");
|
||||
|
||||
return switch (typeAndTarget.enumId) {
|
||||
case create_database_ddl ->
|
||||
new GCPSpannerCreateDatabaseDdlOpDispenser(adapter, op, typeAndTarget.targetFunction);
|
||||
case update_database_ddl ->
|
||||
new GCPSpannerUpdateDatabaseDdlOpDispenser(adapter, op, typeAndTarget.targetFunction);
|
||||
case insert ->
|
||||
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.gcpspanner.opdispensers;
|
||||
|
||||
|
||||
import io.nosqlbench.adapter.gcpspanner.GCPSpannerDriverAdapter;
|
||||
import io.nosqlbench.adapter.gcpspanner.ops.GCPSpannerBaseOp;
|
||||
import io.nosqlbench.adapter.gcpspanner.ops.GCPSpannerCreateDatabaseDdlOp;
|
||||
import io.nosqlbench.adapter.gcpspanner.ops.GCPSpannerUpdateDatabaseDdlOp;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
/**
|
||||
* Dispenser class for creating databases of {@link GCPSpannerCreateDatabaseDdlOp}.
|
||||
*/
|
||||
public class GCPSpannerCreateDatabaseDdlOpDispenser extends GCPSpannerBaseOpDispenser {
|
||||
private static final Logger logger = LogManager.getLogger(GCPSpannerCreateDatabaseDdlOpDispenser.class);
|
||||
private final LongFunction<GCPSpannerCreateDatabaseDdlOp> opFunction;
|
||||
|
||||
/**
|
||||
* Constructor for {@link GCPSpannerCreateDatabaseDdlOpDispenser}.
|
||||
*
|
||||
* @param adapter the {@link GCPSpannerDriverAdapter} instance
|
||||
* @param op the {@link ParsedOp} instance
|
||||
* @param targetFunction a {@link LongFunction} that provides the target string
|
||||
*/
|
||||
public GCPSpannerCreateDatabaseDdlOpDispenser(GCPSpannerDriverAdapter adapter, ParsedOp op, LongFunction<String> targetFunction) {
|
||||
super(adapter, op, targetFunction);
|
||||
this.opFunction = createOpFunction(op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link LongFunction} that generates {@link GCPSpannerUpdateDatabaseDdlOp} instances.
|
||||
*
|
||||
* @param op the {@link ParsedOp} instance
|
||||
* @return a {@link LongFunction} that generates {@link GCPSpannerUpdateDatabaseDdlOp} instances
|
||||
*/
|
||||
private LongFunction<GCPSpannerCreateDatabaseDdlOp> createOpFunction(ParsedOp op) {
|
||||
return (l) -> new GCPSpannerCreateDatabaseDdlOp(
|
||||
spaceFunction.apply(l).getSpanner(),
|
||||
l,
|
||||
targetFunction.apply(l),
|
||||
spaceFunction.apply(l).getDbAdminClient(),
|
||||
spaceFunction.apply(l).getInstanceId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an operation instance based on the provided value.
|
||||
*
|
||||
* @param value the long value used to generate the operation
|
||||
* @return a {@link GCPSpannerBaseOp} instance
|
||||
*/
|
||||
@Override
|
||||
public GCPSpannerBaseOp<?> getOp(long value) {
|
||||
return opFunction.apply(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.gcpspanner.ops;
|
||||
|
||||
import com.google.api.gax.longrunning.OperationFuture;
|
||||
import com.google.cloud.spanner.Database;
|
||||
import com.google.cloud.spanner.DatabaseAdminClient;
|
||||
import com.google.cloud.spanner.Spanner;
|
||||
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
|
||||
|
||||
/**
|
||||
* This class represents an operation to create the database DDL (Data Definition Language) in Google Cloud Spanner.
|
||||
* It extends the {@link GCPSpannerBaseOp} class and provides the implementation for applying the DDL update operation.
|
||||
*/
|
||||
public class GCPSpannerCreateDatabaseDdlOp extends GCPSpannerBaseOp<Long> {
|
||||
private final String createDatbaseStatement;
|
||||
private final DatabaseAdminClient dbAdminClient;
|
||||
private final String instanceId;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link GCPSpannerUpdateDatabaseDdlOp}.
|
||||
*
|
||||
* @param searchIndexClient the {@link Spanner} client
|
||||
* @param requestParam the request parameter
|
||||
* @param createDatbaseStatement the SQL statement to create the table
|
||||
* @param dbAdminClient the {@link DatabaseAdminClient} to execute the DDL update
|
||||
* @param instanceId the instance ID string representing the target spanner instance
|
||||
*/
|
||||
public GCPSpannerCreateDatabaseDdlOp(Spanner searchIndexClient, Long requestParam, String createDatbaseStatement,
|
||||
DatabaseAdminClient dbAdminClient, String instanceId) {
|
||||
super(searchIndexClient, requestParam);
|
||||
this.createDatbaseStatement = createDatbaseStatement;
|
||||
this.dbAdminClient = dbAdminClient;
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the DDL update operation.
|
||||
*
|
||||
* @param value the value to be used in the operation
|
||||
* @return the result of the operation
|
||||
* @throws RuntimeException if an error occurs during the operation
|
||||
*/
|
||||
@Override
|
||||
public Object applyOp(long value) {
|
||||
OperationFuture<Database, CreateDatabaseMetadata> operation = dbAdminClient.createDatabase(
|
||||
instanceId,
|
||||
createDatbaseStatement,
|
||||
null,
|
||||
null);
|
||||
try {
|
||||
return operation.get();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ package io.nosqlbench.adapter.gcpspanner.types;
|
||||
* <a href="https://cloud.google.com/spanner/docs/find-approximate-nearest-neighbors#query-vector-embeddings">here</a></a>
|
||||
*/
|
||||
public enum GCPSpannerOpType {
|
||||
create_database_ddl,
|
||||
update_database_ddl,
|
||||
insert,
|
||||
execute_dml,
|
||||
|
@ -0,0 +1,11 @@
|
||||
scenarios:
|
||||
default:
|
||||
create_table_ddl: run driver=spanner tags==blocks:create_table_ddl service_account_file=TEMPLATE(service_account_file)
|
||||
project_id=TEMPLATE(project_id) instance_id=TEMPLATE(instance_id) database_id=TEMPLATE(database_id) cycles=1
|
||||
|
||||
blocks:
|
||||
create_table_ddl:
|
||||
ops:
|
||||
op1:
|
||||
create_database_ddl: |
|
||||
CREATE DATABASE {database_id}
|
@ -19,12 +19,14 @@ to the adapter at runtime.
|
||||
## Op Templates
|
||||
|
||||
The Google Cloud Spanner adapter supports the following operations:
|
||||
|
||||
* `create_database_ddl` - Data Definition Language operations such as creating and dropping databases.
|
||||
* `update_database_ddl` - Data Definition Language operations such as creating and dropping tables, indexes, etc.
|
||||
* `execute_dml` - Data Manipulation Language operations. Read only operations are supported at this time, including queries
|
||||
and vector queries.
|
||||
* `insert` - Insert a single record, vector or non-vector, of data into the database.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
|
||||
Checkout the sample workload files [here](./activities).
|
||||
---
|
||||
|
Loading…
Reference in New Issue
Block a user