-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[admin] Add create_time to database and table metadata. #289
Open
loserwang1024
wants to merge
1
commit into
alibaba:main
Choose a base branch
from
loserwang1024:create_time
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+913
−35
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
fluss-common/src/main/java/com/alibaba/fluss/metadata/DatabaseDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.fluss.metadata; | ||
|
||
import com.alibaba.fluss.annotation.PublicEvolving; | ||
import com.alibaba.fluss.config.ConfigOption; | ||
import com.alibaba.fluss.config.ConfigurationUtils; | ||
import com.alibaba.fluss.utils.Preconditions; | ||
import com.alibaba.fluss.utils.json.DatabaseDescriptorJsonSerde; | ||
import com.alibaba.fluss.utils.json.JsonSerdeUtils; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents the metadata of a database in Fluss. | ||
* | ||
* <p>It contains all characteristics that can be expressed in a SQL {@code CREATE Database} | ||
* statement, such as schema, primary keys, partition keys, bucket keys, and options. | ||
* | ||
* @since 0.6 | ||
*/ | ||
public class DatabaseDescriptor { | ||
private final Map<String, String> properties; | ||
private final String comment; | ||
|
||
private DatabaseDescriptor(Map<String, String> properties, @Nullable String comment) { | ||
this.properties = properties; | ||
this.comment = comment; | ||
} | ||
|
||
public Map<String, String> getProperties() { | ||
return properties; | ||
} | ||
|
||
public Optional<String> getComment() { | ||
return Optional.ofNullable(comment); | ||
} | ||
|
||
/** | ||
* Serialize the table descriptor to a JSON byte array. | ||
* | ||
* @see DatabaseDescriptorJsonSerde | ||
*/ | ||
public byte[] toJsonBytes() { | ||
return JsonSerdeUtils.writeValueAsBytes(this, DatabaseDescriptorJsonSerde.INSTANCE); | ||
} | ||
|
||
/** | ||
* Deserialize from JSON byte array to an instance of {@link DatabaseDescriptor}. | ||
* | ||
* @see DatabaseDescriptor | ||
*/ | ||
public static DatabaseDescriptor fromJsonBytes(byte[] json) { | ||
return JsonSerdeUtils.readValue(json, DatabaseDescriptorJsonSerde.INSTANCE); | ||
} | ||
|
||
/** Creates a builder for building database descriptor. */ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
|
||
/** Builder for {@link TableDescriptor}. */ | ||
@PublicEvolving | ||
public static class Builder { | ||
|
||
private final Map<String, String> properties; | ||
private @Nullable String comment; | ||
|
||
protected Builder() { | ||
this.properties = new HashMap<>(); | ||
} | ||
|
||
protected Builder(TableDescriptor descriptor) { | ||
this.properties = new HashMap<>(descriptor.getProperties()); | ||
this.comment = descriptor.getComment().orElse(null); | ||
} | ||
|
||
/** | ||
* Sets table property on the table. | ||
* | ||
* <p>Table properties are controlled by Fluss and will change the behavior of the table. | ||
*/ | ||
public <T> Builder property(ConfigOption<T> configOption, T value) { | ||
Preconditions.checkNotNull(configOption, "Config option must not be null."); | ||
Preconditions.checkNotNull(value, "Value must not be null."); | ||
properties.put( | ||
configOption.key(), ConfigurationUtils.convertValue(value, String.class)); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets table property on the table. | ||
* | ||
* <p>Table properties are controlled by Fluss and will change the behavior of the table. | ||
*/ | ||
public Builder property(String key, String value) { | ||
Preconditions.checkNotNull(key, "Key must not be null."); | ||
Preconditions.checkNotNull(value, "Value must not be null."); | ||
properties.put(key, value); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets table properties on the table. | ||
* | ||
* <p>Table properties are controlled by Fluss and will change the behavior of the table. | ||
*/ | ||
public Builder properties(Map<String, String> properties) { | ||
Preconditions.checkNotNull(properties, "properties must not be null."); | ||
this.properties.putAll(properties); | ||
return this; | ||
} | ||
|
||
/** Define the comment for this table. */ | ||
public Builder comment(@Nullable String comment) { | ||
this.comment = comment; | ||
return this; | ||
} | ||
|
||
/** Returns an immutable instance of {@link TableDescriptor}. */ | ||
public DatabaseDescriptor build() { | ||
return new DatabaseDescriptor(properties, comment); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
fluss-common/src/main/java/com/alibaba/fluss/metadata/DatabaseInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.fluss.metadata; | ||
|
||
/** | ||
* Information of a database metadata, includes {@link DatabaseDescriptor}. | ||
* | ||
* @since 0.6 | ||
*/ | ||
public class DatabaseInfo { | ||
private final String databaseName; | ||
private final DatabaseDescriptor databaseDescriptor; | ||
private final long createTime; | ||
private final long modifyTime; | ||
|
||
public DatabaseInfo( | ||
String databaseName, | ||
DatabaseDescriptor databaseDescriptor, | ||
long createTime, | ||
long modifyTime) { | ||
this.databaseName = databaseName; | ||
this.databaseDescriptor = databaseDescriptor; | ||
this.createTime = createTime; | ||
this.modifyTime = modifyTime; | ||
} | ||
|
||
public String getDatabaseName() { | ||
return databaseName; | ||
} | ||
|
||
public DatabaseDescriptor getDatabaseDescriptor() { | ||
return databaseDescriptor; | ||
} | ||
|
||
public long getCreateTime() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return createTime; | ||
} | ||
|
||
public long getModifyTime() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return modifyTime; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert the properties size is 1