Skip to content

Commit

Permalink
[#676] feat(jdbc): Support jdbc operations in JDBC catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
Clearvive authored and Clearvive committed Nov 17, 2023
1 parent 8b0f23f commit 8977c1a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,10 @@ public void initialize(Map<String, String> conf) throws RuntimeException {
// Key format like gravitino.bypass.a.b
Map<String, String> resultConf =
Maps.newHashMap(MapUtils.getPrefixMap(conf, CATALOG_BYPASS_PREFIX));
this.jdbcCatalogPropertiesMetadata = new JdbcCatalogPropertiesMetadata();
// Hold keys that lie in GRAVITINO_CONFIG_TO_JDBC
Map<String, String> gravitinoConfig =
this.jdbcCatalogPropertiesMetadata.transformProperties(conf);

resultConf.putAll(gravitinoConfig);

JdbcConfig jdbcConfig = new JdbcConfig(resultConf);
dataSource = DataSourceUtils.createDataSource(jdbcConfig);
this.dataSource = DataSourceUtils.createDataSource(jdbcConfig);
this.jdbcDatabaseOperations.initialize(dataSource, exceptionConverter);
this.jdbcCatalogPropertiesMetadata = new JdbcCatalogPropertiesMetadata();
this.jdbcTablePropertiesMetadata = new JdbcTablePropertiesMetadata();
this.jdbcSchemaPropertiesMetadata = new JdbcSchemaPropertiesMetadata();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,13 @@
import com.datastrato.gravitino.catalog.PropertyEntry;
import com.datastrato.gravitino.catalog.jdbc.config.JdbcConfig;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;

public class JdbcCatalogPropertiesMetadata extends BaseCatalogPropertiesMetadata {
private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;

public static final Map<String, String> GRAVITINO_CONFIG_TO_JDBC =
ImmutableMap.<String, String>builder()
.put(JdbcConfig.JDBC_URL.getKey(), JdbcConfig.JDBC_URL.getKey())
.put(JdbcConfig.USERNAME.getKey(), JdbcConfig.USERNAME.getKey())
.put(JdbcConfig.PASSWORD.getKey(), JdbcConfig.PASSWORD.getKey())
.put(JdbcConfig.POOL_MIN_IDLE.getKey(), JdbcConfig.POOL_MIN_IDLE.getKey())
.put(JdbcConfig.POOL_MAX_SIZE.getKey(), JdbcConfig.POOL_MAX_SIZE.getKey())
.build();;

static {
List<PropertyEntry<?>> propertyEntries =
ImmutableList.of(
Expand Down Expand Up @@ -60,15 +50,4 @@ public class JdbcCatalogPropertiesMetadata extends BaseCatalogPropertiesMetadata
protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
return PROPERTIES_METADATA;
}

public Map<String, String> transformProperties(Map<String, String> conf) {
Map<String, String> gravitinoConfig = Maps.newHashMap();
conf.forEach(
(key, value) -> {
if (GRAVITINO_CONFIG_TO_JDBC.containsKey(key)) {
gravitinoConfig.put(GRAVITINO_CONFIG_TO_JDBC.get(key), value);
}
});
return gravitinoConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,4 @@ public JdbcConfig(Map<String, String> properties) {
loadFromMap(properties, k -> true);
assert null != getJdbcUrl();
}

public Map<String, String> getAllProperties() {
return getConfigsWithPrefix("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static DataSource createDBCPDataSource(JdbcConfig jdbcConfig) throws Exc

private static Properties getProperties(JdbcConfig jdbcConfig) {
Properties properties = new Properties();
properties.putAll(jdbcConfig.getAllProperties());
properties.putAll(jdbcConfig.getAllConfig());
return properties;
}

Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/com/datastrato/gravitino/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public Map<String, String> getConfigsWithPrefix(String prefix) {
return MapUtils.getPrefixMap(configMap, prefix);
}

public Map<String, String> getAllConfig() {
return MapUtils.unmodifiableMap(configMap);
}

/**
* Sets the value of a configuration entry.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public static Map<String, String> getPrefixMap(Map<String, String> m, String pre

return Collections.unmodifiableMap(configs);
}

public static Map<String, String> unmodifiableMap(Map<String, String> m) {
return Collections.unmodifiableMap(m);
}
}

0 comments on commit 8977c1a

Please sign in to comment.