From df7888120bd2081c4f4ced8ebf8eff2f32bb66e6 Mon Sep 17 00:00:00 2001 From: Jishnu J Date: Tue, 3 Dec 2024 16:05:15 +0530 Subject: [PATCH] Enum, constants for data loader --- .../scalar/db/dataloader/core/Constants.java | 27 ++++++++ .../db/dataloader/core/DatabaseKeyType.java | 7 ++ .../db/dataloader/core/ErrorMessage.java | 64 +++++++++++++++++++ .../db/dataloader/core/ScalarDBMode.java | 7 ++ .../scalar/db/dataloader/core/ScanRange.java | 19 ++++++ 5 files changed, 124 insertions(+) create mode 100644 data-loader/core/src/main/java/com/scalar/db/dataloader/core/Constants.java create mode 100644 data-loader/core/src/main/java/com/scalar/db/dataloader/core/DatabaseKeyType.java create mode 100644 data-loader/core/src/main/java/com/scalar/db/dataloader/core/ErrorMessage.java create mode 100644 data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScalarDBMode.java create mode 100644 data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScanRange.java diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/Constants.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/Constants.java new file mode 100644 index 000000000..09759bf5b --- /dev/null +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/Constants.java @@ -0,0 +1,27 @@ +package com.scalar.db.dataloader.core; + +/** The constants that are used in the com.scalar.dataloader.core package */ +public class Constants { + + public static final String IMPORT_LOG_ENTRY_STATUS_FIELD = "data_loader_import_status"; + public static final String TABLE_LOOKUP_KEY_FORMAT = "%s.%s"; + + public static final String LOG_UPDATE_SUCCESS = "Row %s has been updated in table %s.%s"; + public static final String LOG_INSERT_SUCCESS = "Row %s has been inserted into table %s.%s"; + public static final String LOG_IMPORT_VALIDATION = "Validating data for line %s ..."; + public static final String LOG_IMPORT_GET_DATA = + "Retrieving existing data record from database ..."; + public static final String LOG_IMPORT_LINE_SUCCESS = "Row %s import is completed"; + public static final String LOG_IMPORT_LINE_FAILED = "Row %s import has failed: %s"; + public static final String LOG_IMPORT_COMPLETED = + "The import process has been completed. Please check the success and failed output files for a detailed report"; + + public static final String LOG_SCANNING_START = "Retrieving data from %s.%s table ..."; + public static final String LOG_CONVERTING = "Converting %s.%s data to %s ..."; + public static final String MISSING_CSV_HEADERS = + "Valid headers are not present or missing in the provided CSV file"; + public static final String ERROR_MISSING_SOURCE_FIELD = + "the data mapping source field '%s' for table '%s' is missing in the json data record"; + public static final String ABORT_TRANSACTION_STATUS = + "Transaction aborted as part of batch transaction aborted"; +} diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/DatabaseKeyType.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/DatabaseKeyType.java new file mode 100644 index 000000000..b1926740a --- /dev/null +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/DatabaseKeyType.java @@ -0,0 +1,7 @@ +package com.scalar.db.dataloader.core; + +/** Type of key in database */ +public enum DatabaseKeyType { + PARTITION, + CLUSTERING +} diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ErrorMessage.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ErrorMessage.java new file mode 100644 index 000000000..c9b7e01b6 --- /dev/null +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ErrorMessage.java @@ -0,0 +1,64 @@ +package com.scalar.db.dataloader.core; + +/*** + * The error messages used in the com.scalar.dataloader.core package + */ +public class ErrorMessage { + public static final String ERROR_MISSING_NAMESPACE_OR_TABLE = + "the provided namespace '%s' and/or table name '%s' is incorrect and could not be found"; + public static final String ERROR_MISSING_COLUMN = "missing field or column mapping for %s"; + public static final String ERROR_MISSING_PARTITION_KEY_COLUMN = + "missing required field or column mapping for partition key %s"; + public static final String ERROR_MISSING_CLUSTERING_KEY_COLUMN = + "missing required field or column mapping for clustering key %s"; + public static final String ERROR_CRUD_EXCEPTION = + "something went wrong while trying to save the data"; + public static final String ERROR_DATA_ALREADY_EXISTS = "record already exists"; + public static final String ERROR_DATA_NOT_FOUND = "record was not found"; + public static final String ERROR_CONTROL_FILE_MISSING_DATA_MAPPINGS = + "the control file is missing data mappings"; + public static final String ERROR_TARGET_COLUMN_NOT_FOUND = + "The target column '%s' for source field '%s' could not be found in table '%s'"; + public static final String ERROR_MISSING_PARTITION_KEY = + "The required partition key '%s' is missing in the control file mapping for table '%s'"; + public static final String ERROR_MISSING_CLUSTERING_KEY = + "The required clustering key '%s' is missing in the control file mapping for table '%s'"; + public static final String ERROR_MISSING_SOURCE_FIELD = + "the data mapping source field '%s' for table '%s' is missing in the json data record"; + public static final String ERROR_DUPLICATE_DATA_MAPPINGS = + "Duplicate data mappings found for table '%s' in the control file"; + public static final String ERROR_MISSING_COLUMN_MAPPING = + "No mapping found for column '%s' in table '%s' in the control file. \nControl file validation set at 'FULL'. All columns need to be mapped."; + public static final String ERROR_MULTIPLE_MAPPINGS_FOR_COLUMN_FOUND = + "Multiple data mappings found for column '%s' in table '%s'"; + public static final String ERROR_METHOD_NULL_ARGUMENT = "Method null argument not allowed"; + public static final String ERROR_COULD_NOT_FIND_PARTITION_KEY = + "could not find the partition key"; + public static final String ERROR_METADATA_OR_DATA_TYPES_NOT_FOUND = + "no table meta data or a data type map was found for %s.%s"; + public static final String ERROR_EMPTY_SOURCE_ROW = + "The source record data was undefined or empty"; + public static final String ERROR_UPSERT_INSERT_MISSING_COLUMNS = + "The source record needs to contain all fields if the UPSERT turns into an INSERT"; + public static final String ERROR_SCAN_FAILED = "Could not complete the scan"; + public static final String ERROR_UNKNOWN_TRANSACTION_STATUS = + "Error : the transaction to retrieve the account is in an unknown state"; + public static final String ERROR_INVALID_PROJECTION = "The column '%s' was not found"; + public static final String ERROR_SCAN = + "Something went wrong while scanning. Are you sure you are running in the correct transaction mode?"; + public static final String ERROR_CLUSTERING_KEY_NOT_FOUND = + "The provided clustering key %s was not found"; + public static final String ERROR_KEY_NOT_FOUND = "The key '%s' could not be found"; + public static final String ERROR_KEY_FORMATTING = + "They provided key '%s is not formatted correctly. Expected format is field=value."; + public static final String ERROR_SORT_FORMATTING = + "They provided sort '%s is not formatted correctly. Expected format is field=asc|desc."; + public static final String ERROR_VALUE_TO_STRING_CONVERSION_FAILED = + "Something went wrong while converting the ScalarDB values to strings. The table metadata and Value datatype probably do not match."; + public static final String ERROR_BASE64_ENCODING = + "Invalid base64 encoding for blob value for column %s"; + public static final String ERROR_NUMBER_FORMAT_EXCEPTION = + "Invalid number specified for column %s"; + public static final String ERROR_NULL_POINTER_EXCEPTION = + "The %s column does not support a null value"; +} diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScalarDBMode.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScalarDBMode.java new file mode 100644 index 000000000..b7326ccb4 --- /dev/null +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScalarDBMode.java @@ -0,0 +1,7 @@ +package com.scalar.db.dataloader.core; + +/** The available modes a ScalarDB instance can run in */ +public enum ScalarDBMode { + STORAGE, + TRANSACTION +} diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScanRange.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScanRange.java new file mode 100644 index 000000000..1a7239cb1 --- /dev/null +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/ScanRange.java @@ -0,0 +1,19 @@ +package com.scalar.db.dataloader.core; + +import com.scalar.db.io.Key; +import lombok.Value; + +/*** + * The scan range which is used in data export scan filtering + */ +@Value +public class ScanRange { + /** The key for scan start filter */ + Key scanStartKey; + /** The key for scan end filter */ + Key scanEndKey; + /** To include the scan start key value in the export data scan */ + boolean isStartInclusive; + /** To include the scan end key value in the export data scan */ + boolean isEndInclusive; +}