Interface MongoConfig
-
- All Superinterfaces:
java.io.Serializable
- All Known Implementing Classes:
ReadConfig
,WriteConfig
public interface MongoConfig extends java.io.Serializable
The MongoConfig interface.Provides MongoDB specific configuration.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLIENT_FACTORY_CONFIG
The MongoClientFactory configuration keystatic java.lang.String
CLIENT_FACTORY_DEFAULT
The default MongoClientFactory configuration valuestatic java.lang.String
COLLECTION_NAME_CONFIG
The collection name configstatic java.lang.String
COMMENT_CONFIG
Add a comment to mongodb operationsstatic java.lang.String
CONNECTION_STRING_CONFIG
The connection string configuration keystatic java.lang.String
CONNECTION_STRING_DEFAULT
The default connection string configuration valuestatic java.lang.String
DATABASE_NAME_CONFIG
The database name configstatic java.lang.String
PREFIX
The prefix for all general Spark MongoDB configurations.static java.lang.String
READ_PREFIX
The prefix for specific output (read) based configurations.static java.lang.String
WRITE_PREFIX
The prefix for specific input (write) based configurations.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default boolean
containsKey(java.lang.String key)
Returnstrue
if this map contains a mapping for the specified key.static MongoConfig
createConfig(java.util.Map<java.lang.String,java.lang.String> options)
Create a Mongo Configuration that does not yet have a fixed use casedefault java.lang.String
get(java.lang.String key)
Returns the value to which the specified key is mappeddefault boolean
getBoolean(java.lang.String key, boolean defaultValue)
Returns the boolean value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.default java.lang.String
getCollectionName()
default @Nullable org.bson.BsonString
getComment()
default com.mongodb.ConnectionString
getConnectionString()
default java.lang.String
getDatabaseName()
default double
getDouble(java.lang.String key, double defaultValue)
Returns the double value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.default int
getInt(java.lang.String key, int defaultValue)
Returns the int value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.default java.util.List<java.lang.String>
getList(java.lang.String key, java.util.List<java.lang.String> defaultValue)
Returns a list of strings from a comma delimited string to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.default long
getLong(java.lang.String key, long defaultValue)
Returns the long value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.default com.mongodb.MongoNamespace
getNamespace()
java.util.Map<java.lang.String,java.lang.String>
getOptions()
default java.lang.String
getOrDefault(java.lang.String key, java.lang.String defaultValue)
Returns the value to which the specified key is mapped, ordefaultValue
if this config contains no mapping for the key.java.util.Map<java.lang.String,java.lang.String>
getOriginals()
static ReadConfig
readConfig(java.util.Map<java.lang.String,java.lang.String> options)
Create a Read Configurationdefault MongoConfig
subConfiguration(java.lang.String prefix)
Gets all configurations starting with a prefix.default ReadConfig
toReadConfig()
default WriteConfig
toWriteConfig()
MongoConfig
withOption(java.lang.String key, java.lang.String value)
Return aMongoConfig
instance with the extra options applied.MongoConfig
withOptions(java.util.Map<java.lang.String,java.lang.String> options)
Return aMongoConfig
instance with the extra options applied.static WriteConfig
writeConfig(java.util.Map<java.lang.String,java.lang.String> options)
Create a Write Configuration
-
-
-
Field Detail
-
PREFIX
static final java.lang.String PREFIX
The prefix for all general Spark MongoDB configurations.For example the
CONNECTION_STRING_CONFIG
should be defined as: "spark.mongodb.connection.uri
"."spark.mongodb."
- See Also:
- Constant Field Values
-
WRITE_PREFIX
static final java.lang.String WRITE_PREFIX
The prefix for specific input (write) based configurations.Overrides any configurations that just use the
PREFIX
. For example to override theCONNECTION_STRING_CONFIG
just for inputting data into MongoDB: "spark.mongodb.input.connection.uri
"."spark.mongodb.write."
- See Also:
- Constant Field Values
-
READ_PREFIX
static final java.lang.String READ_PREFIX
The prefix for specific output (read) based configurations.Overrides any configurations that just use the
PREFIX
. For example to override theCONNECTION_STRING_CONFIG
just for outputting data from MongoDB: "spark.mongodb.output.connection.uri
"."spark.mongodb.read."
- See Also:
- Constant Field Values
-
CLIENT_FACTORY_CONFIG
static final java.lang.String CLIENT_FACTORY_CONFIG
The MongoClientFactory configuration keyThe default implementation uses the
CONNECTION_STRING_CONFIG
as the connection string.Custom implementations are allowed and must implement the
MongoClientFactory
interface."mongoClientFactory"
- See Also:
- Constant Field Values
-
CLIENT_FACTORY_DEFAULT
static final java.lang.String CLIENT_FACTORY_DEFAULT
The default MongoClientFactory configuration valueRequires the
CONNECTION_STRING_CONFIG
for configuring the resultingMongoClient
-
CONNECTION_STRING_CONFIG
static final java.lang.String CONNECTION_STRING_CONFIG
The connection string configuration key"connection.uri"
- See Also:
- Constant Field Values
-
CONNECTION_STRING_DEFAULT
static final java.lang.String CONNECTION_STRING_DEFAULT
The default connection string configuration value"mongodb://localhost:27017/"
- See Also:
- Constant Field Values
-
DATABASE_NAME_CONFIG
static final java.lang.String DATABASE_NAME_CONFIG
The database name config"database"
- See Also:
- Constant Field Values
-
COLLECTION_NAME_CONFIG
static final java.lang.String COLLECTION_NAME_CONFIG
The collection name config"collection"
- See Also:
- Constant Field Values
-
COMMENT_CONFIG
static final java.lang.String COMMENT_CONFIG
Add a comment to mongodb operationsAllows debugging and profiling queries from the connector.
"comment"
See: $comment
Note: Requires MongoDB 4.6+
- See Also:
- Constant Field Values
-
-
Method Detail
-
createConfig
@Internal static MongoConfig createConfig(java.util.Map<java.lang.String,java.lang.String> options)
Create a Mongo Configuration that does not yet have a fixed use caseCan be used to create partial configurations or a MongoConfig which will later be turned into a
ReadConfig
orWriteConfig
- Parameters:
options
- the configuration options- Returns:
- a simple configuration
- See Also:
MongoTableProvider.getTable(org.apache.spark.sql.types.StructType, org.apache.spark.sql.connector.expressions.Transform[], Map)
-
readConfig
static ReadConfig readConfig(java.util.Map<java.lang.String,java.lang.String> options)
Create a Read Configuration- Parameters:
options
- the configuration options- Returns:
- the read configuration
-
writeConfig
static WriteConfig writeConfig(java.util.Map<java.lang.String,java.lang.String> options)
Create a Write Configuration- Parameters:
options
- the configuration options- Returns:
- the write configuration
-
getOptions
java.util.Map<java.lang.String,java.lang.String> getOptions()
- Returns:
- the options for this MongoConfig instance
-
withOption
MongoConfig withOption(java.lang.String key, java.lang.String value)
Return aMongoConfig
instance with the extra options applied.Existing configurations may be overwritten by the new options.
- Parameters:
key
- the key to addvalue
- the value to add- Returns:
- a new MongoConfig
-
withOptions
MongoConfig withOptions(java.util.Map<java.lang.String,java.lang.String> options)
Return aMongoConfig
instance with the extra options applied.Existing configurations may be overwritten by the new options.
- Parameters:
options
- the context specific options.- Returns:
- a new MongoConfig
-
getOriginals
java.util.Map<java.lang.String,java.lang.String> getOriginals()
- Returns:
- the original options for this MongoConfig instance
-
getConnectionString
default com.mongodb.ConnectionString getConnectionString()
- Returns:
- the connection string
-
getNamespace
default com.mongodb.MongoNamespace getNamespace()
- Returns:
- the namespace related to this config
-
getDatabaseName
default java.lang.String getDatabaseName()
- Returns:
- the database name to use for this configuration
-
getCollectionName
default java.lang.String getCollectionName()
- Returns:
- the collection name to use for this configuration
-
toReadConfig
default ReadConfig toReadConfig()
- Returns:
- the read config
-
toWriteConfig
default WriteConfig toWriteConfig()
- Returns:
- the write config
-
subConfiguration
default MongoConfig subConfiguration(java.lang.String prefix)
Gets all configurations starting with a prefix.Note: The prefix will be removed from the keys in the resulting configuration.
- Parameters:
prefix
- for the configuration options that should be returned- Returns:
- the configuration options that started with the prefix
-
containsKey
default boolean containsKey(java.lang.String key)
Returnstrue
if this map contains a mapping for the specified key.- Parameters:
key
- key whose presence in this map is to be tested- Returns:
true
if this map contains a mapping for the specified key
-
get
default java.lang.String get(java.lang.String key)
Returns the value to which the specified key is mapped- Parameters:
key
- the key whose associated value is to be returned. The key match is case-insensitive.- Returns:
- the value to which the specified key is mapped or null.
-
getOrDefault
default java.lang.String getOrDefault(java.lang.String key, java.lang.String defaultValue)
Returns the value to which the specified key is mapped, ordefaultValue
if this config contains no mapping for the key.Note: The key match is case-insensitive.
- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the default mapping for the config- Returns:
- the value to which the specified key is mapped, or
defaultValue
if this config contains no mapping for the key or the mapping returns null. The key match is case-insensitive. - Throws:
java.lang.ClassCastException
- if the key is of an inappropriate type for this map
-
getBoolean
default boolean getBoolean(java.lang.String key, boolean defaultValue)
Returns the boolean value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the default mapping for the config- Returns:
- the boolean value to which the specified key is mapped, or
defaultValue
if there is no mapping for the key. The key match is case-insensitive. - Throws:
java.lang.IllegalArgumentException
- if the specified key cannot be converted into a valid boolean
-
getInt
default int getInt(java.lang.String key, int defaultValue)
Returns the int value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the default mapping for the config- Returns:
- the integer value to which the specified key is mapped, or
defaultValue
if there is no mapping for the key. The key match is case-insensitive. - Throws:
java.lang.NumberFormatException
- if the specified key cannot be converted into a valid int
-
getLong
default long getLong(java.lang.String key, long defaultValue)
Returns the long value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the default mapping for the config- Returns:
- the long value to which the specified key is mapped, or
defaultValue
if there is no mapping for the key. The key match is case-insensitive. - Throws:
java.lang.NumberFormatException
- if the specified key cannot be converted into a valid long
-
getDouble
default double getDouble(java.lang.String key, double defaultValue)
Returns the double value to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the default mapping for the config- Returns:
- the double value to which the specified key is mapped, or
defaultValue
if there is no mapping for the key. The key match is case-insensitive. - Throws:
java.lang.NumberFormatException
- if the specified key cannot be converted into a valid double
-
getList
default java.util.List<java.lang.String> getList(java.lang.String key, java.util.List<java.lang.String> defaultValue)
Returns a list of strings from a comma delimited string to which the specified key is mapped, ordefaultValue
if there is no mapping for the key.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the default mapping for the config- Returns:
- a list of strings to which the specified key is mapped, or
defaultValue
if there is no mapping for the key. The key match is case-insensitive.
-
getComment
@Nullable default @Nullable org.bson.BsonString getComment()
- Returns:
- the comment to be associated with an operation or null if not set
-
-