Skip to content

Commit

Permalink
Merge branch 'main' into doc-glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
tengqm authored Dec 11, 2024
2 parents 39f83a1 + 26a8b37 commit 6d9eba8
Show file tree
Hide file tree
Showing 103 changed files with 921 additions and 8,165 deletions.
1 change: 0 additions & 1 deletion LICENSE.bin
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@

JSR305
LevelDB JNI
RocksDB JNI
JCraft
Javolution
ANTLR4
Expand Down
1 change: 0 additions & 1 deletion LICENSE.rest
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@
JSR305
LevelDB JNI
Protobuf
RocksDB JNI
Stax2 API
XMLenc

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.gravitino.credential;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;

/** OSS secret key credential. */
public class OSSSecretKeyCredential implements Credential {

/** OSS secret key credential type. */
public static final String OSS_SECRET_KEY_CREDENTIAL_TYPE = "oss-secret-key";
/** The static access key ID used to access OSS data. */
public static final String GRAVITINO_OSS_STATIC_ACCESS_KEY_ID = "oss-access-key-id";
/** The static secret access key used to access OSS data. */
public static final String GRAVITINO_OSS_STATIC_SECRET_ACCESS_KEY = "oss-secret-access-key";

private String accessKeyId;
private String secretAccessKey;

/**
* Constructs an instance of {@link OSSSecretKeyCredential} with the static OSS access key ID and
* secret access key.
*
* @param accessKeyId The OSS static access key ID.
* @param secretAccessKey The OSS static secret access key.
*/
public OSSSecretKeyCredential(String accessKeyId, String secretAccessKey) {
validate(accessKeyId, secretAccessKey, 0);
this.accessKeyId = accessKeyId;
this.secretAccessKey = secretAccessKey;
}

/**
* This is the constructor that is used by credential factory to create an instance of credential
* according to the credential information.
*/
public OSSSecretKeyCredential() {}

@Override
public String credentialType() {
return OSS_SECRET_KEY_CREDENTIAL_TYPE;
}

@Override
public long expireTimeInMs() {
return 0;
}

@Override
public Map<String, String> credentialInfo() {
return (new ImmutableMap.Builder<String, String>())
.put(GRAVITINO_OSS_STATIC_ACCESS_KEY_ID, accessKeyId)
.put(GRAVITINO_OSS_STATIC_SECRET_ACCESS_KEY, secretAccessKey)
.build();
}

/**
* Initialize the credential with the credential information.
*
* <p>This method is invoked to deserialize the credential in client side.
*
* @param credentialInfo The credential information from {@link #credentialInfo}.
* @param expireTimeInMs The expire-time from {@link #expireTimeInMs()}.
*/
@Override
public void initialize(Map<String, String> credentialInfo, long expireTimeInMs) {
String accessKeyId = credentialInfo.get(GRAVITINO_OSS_STATIC_ACCESS_KEY_ID);
String secretAccessKey = credentialInfo.get(GRAVITINO_OSS_STATIC_SECRET_ACCESS_KEY);
validate(accessKeyId, secretAccessKey, expireTimeInMs);
this.accessKeyId = accessKeyId;
this.secretAccessKey = secretAccessKey;
}

/**
* Get OSS static access key ID.
*
* @return The OSS access key ID.
*/
public String accessKeyId() {
return accessKeyId;
}

/**
* Get OSS static secret access key.
*
* @return The OSS secret access key.
*/
public String secretAccessKey() {
return secretAccessKey;
}

private void validate(String accessKeyId, String secretAccessKey, long expireTimeInMs) {
Preconditions.checkArgument(
StringUtils.isNotBlank(accessKeyId), "OSS access key Id should not empty");
Preconditions.checkArgument(
StringUtils.isNotBlank(secretAccessKey), "OSS secret access key should not empty");
Preconditions.checkArgument(
expireTimeInMs == 0, "The expire time of OSSSecretKeyCredential is not 0");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ org.apache.gravitino.credential.S3TokenCredential
org.apache.gravitino.credential.S3SecretKeyCredential
org.apache.gravitino.credential.GCSTokenCredential
org.apache.gravitino.credential.OSSTokenCredential
org.apache.gravitino.credential.OSSSecretKeyCredential
88 changes: 43 additions & 45 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -303,51 +303,49 @@ subprojects {
}
}

if (project.name != "meta") {
apply(plugin = "net.ltgt.errorprone")
dependencies {
errorprone("com.google.errorprone:error_prone_core:2.10.0")
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone.isEnabled.set(true)
options.errorprone.disableWarningsInGeneratedCode.set(true)
options.errorprone.disable(
"AlmostJavadoc",
"CanonicalDuration",
"CheckReturnValue",
"ComparableType",
"ConstantOverflow",
"DoubleBraceInitialization",
"EqualsUnsafeCast",
"EmptyBlockTag",
"FutureReturnValueIgnored",
"InconsistentCapitalization",
"InconsistentHashCode",
"JavaTimeDefaultTimeZone",
"JdkObsolete",
"LockNotBeforeTry",
"MissingSummary",
"MissingOverride",
"MutableConstantField",
"NonOverridingEquals",
"ObjectEqualsForPrimitives",
"OperatorPrecedence",
"ReturnValueIgnored",
"SameNameButDifferent",
"StaticAssignmentInConstructor",
"StringSplitter",
"ThreadPriorityCheck",
"ThrowIfUncheckedKnownChecked",
"TypeParameterUnusedInFormals",
"UnicodeEscape",
"UnnecessaryParentheses",
"UnsafeReflectiveConstructionCast",
"UnusedMethod",
"VariableNameSameAsType",
"WaitNotInLoop"
)
}
apply(plugin = "net.ltgt.errorprone")
dependencies {
errorprone("com.google.errorprone:error_prone_core:2.10.0")
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone.isEnabled.set(true)
options.errorprone.disableWarningsInGeneratedCode.set(true)
options.errorprone.disable(
"AlmostJavadoc",
"CanonicalDuration",
"CheckReturnValue",
"ComparableType",
"ConstantOverflow",
"DoubleBraceInitialization",
"EqualsUnsafeCast",
"EmptyBlockTag",
"FutureReturnValueIgnored",
"InconsistentCapitalization",
"InconsistentHashCode",
"JavaTimeDefaultTimeZone",
"JdkObsolete",
"LockNotBeforeTry",
"MissingSummary",
"MissingOverride",
"MutableConstantField",
"NonOverridingEquals",
"ObjectEqualsForPrimitives",
"OperatorPrecedence",
"ReturnValueIgnored",
"SameNameButDifferent",
"StaticAssignmentInConstructor",
"StringSplitter",
"ThreadPriorityCheck",
"ThrowIfUncheckedKnownChecked",
"TypeParameterUnusedInFormals",
"UnicodeEscape",
"UnnecessaryParentheses",
"UnsafeReflectiveConstructionCast",
"UnusedMethod",
"VariableNameSameAsType",
"WaitNotInLoop"
)
}

tasks.withType<Javadoc> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.gravitino.oss.credential;

import java.util.Map;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.credential.CredentialContext;
import org.apache.gravitino.credential.CredentialProvider;
import org.apache.gravitino.credential.OSSSecretKeyCredential;
import org.apache.gravitino.credential.config.OSSCredentialConfig;

/** Generate OSS access key and secret key to access OSS data. */
public class OSSSecretKeyProvider implements CredentialProvider {

private String accessKey;
private String secretKey;

@Override
public void initialize(Map<String, String> properties) {
OSSCredentialConfig ossCredentialConfig = new OSSCredentialConfig(properties);
this.accessKey = ossCredentialConfig.accessKeyID();
this.secretKey = ossCredentialConfig.secretAccessKey();
}

@Override
public void close() {}

@Override
public String credentialType() {
return OSSSecretKeyCredential.OSS_SECRET_KEY_CREDENTIAL_TYPE;
}

@Override
public Credential getCredential(CredentialContext context) {
return new OSSSecretKeyCredential(accessKey, secretKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#
org.apache.gravitino.oss.credential.OSSTokenProvider
org.apache.gravitino.oss.credential.OSSTokenProvider
org.apache.gravitino.oss.credential.OSSSecretKeyProvider
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static org.apache.gravitino.Configs.ENTITY_RELATIONAL_JDBC_BACKEND_URL;
import static org.apache.gravitino.Configs.ENTITY_RELATIONAL_JDBC_BACKEND_USER;
import static org.apache.gravitino.Configs.ENTITY_RELATIONAL_STORE;
import static org.apache.gravitino.Configs.ENTITY_SERDE;
import static org.apache.gravitino.Configs.ENTITY_STORE;
import static org.apache.gravitino.Configs.RELATIONAL_ENTITY_STORE;
import static org.apache.gravitino.Configs.STORE_DELETE_AFTER_TIME;
Expand Down Expand Up @@ -189,7 +188,6 @@ public static void setUp() {
when(config.get(VERSION_RETENTION_COUNT)).thenReturn(1L);
when(config.get(STORE_TRANSACTION_MAX_SKEW_TIME)).thenReturn(1000L);
when(config.get(STORE_DELETE_AFTER_TIME)).thenReturn(20 * 60 * 1000L);
when(config.get(ENTITY_SERDE)).thenReturn("proto");

store = EntityStoreFactory.createEntityStore(config);
store.initialize(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/** Type converter for MySQL. */
public class MysqlTypeConverter extends JdbcTypeConverter {

static final String BIT = "bit";
static final String TINYINT = "tinyint";
static final String TINYINT_UNSIGNED = "tinyint unsigned";
static final String SMALLINT = "smallint";
Expand All @@ -43,6 +44,11 @@ public class MysqlTypeConverter extends JdbcTypeConverter {
@Override
public Type toGravitino(JdbcTypeBean typeBean) {
switch (typeBean.getTypeName().toLowerCase()) {
case BIT:
if (typeBean.getColumnSize() == null || typeBean.getColumnSize() == 1) {
return Types.BooleanType.get();
}
return Types.BinaryType.get();
case TINYINT:
return Types.ByteType.get();
case TINYINT_UNSIGNED:
Expand Down Expand Up @@ -139,6 +145,8 @@ public String fromGravitino(Type type) {
return type.simpleString();
} else if (type instanceof Types.BinaryType) {
return type.simpleString();
} else if (type instanceof Types.BooleanType) {
return BIT;
} else if (type instanceof Types.ExternalType) {
return ((Types.ExternalType) type).catalogString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,9 @@ void testColumnTypeConverter() {
+ " varchar20_col varchar(20),\n"
+ " text_col text,\n"
+ " binary_col binary,\n"
+ " blob_col blob\n"
+ " blob_col blob,\n"
+ " bit_col_8 bit(8),\n"
+ " bit_col bit\n"
+ ");\n";

mysqlService.executeQuery(sql);
Expand Down Expand Up @@ -694,6 +696,12 @@ void testColumnTypeConverter() {
case "binary_col":
Assertions.assertEquals(Types.BinaryType.get(), column.dataType());
break;
case "bit_col_8":
Assertions.assertEquals(Types.BinaryType.get(), column.dataType());
break;
case "bit_col":
Assertions.assertEquals(Types.BooleanType.get(), column.dataType());
break;
case "blob_col":
Assertions.assertEquals(Types.ExternalType.of("BLOB"), column.dataType());
break;
Expand Down Expand Up @@ -1691,13 +1699,13 @@ void testMySQLSchemaNameCaseSensitive() {
}

@Test
void testUnparsedTypeConverter() {
void testParsedBitTypeConverter() {
String tableName = GravitinoITUtils.genRandomName("test_unparsed_type");
mysqlService.executeQuery(
String.format("CREATE TABLE %s.%s (bit_col bit);", schemaName, tableName));
Table loadedTable =
catalog.asTableCatalog().loadTable(NameIdentifier.of(schemaName, tableName));
Assertions.assertEquals(Types.ExternalType.of("BIT"), loadedTable.columns()[0].dataType());
Assertions.assertEquals(Types.BooleanType.get(), loadedTable.columns()[0].dataType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ public void testCreateNotSupportTypeTable() {
List<JdbcColumn> columns = new ArrayList<>();
List<Type> notSupportType =
Arrays.asList(
Types.BooleanType.get(),
Types.FixedType.of(10),
Types.IntervalDayType.get(),
Types.IntervalYearType.get(),
Expand Down
Loading

0 comments on commit 6d9eba8

Please sign in to comment.