-
Notifications
You must be signed in to change notification settings - Fork 119
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
[Draft] Refactor config classes #312
base: main
Are you sure you want to change the base?
Changes from 1 commit
30c4d71
ee62876
e59055b
c05eead
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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 io.onetable.client; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
import org.apache.hadoop.fs.Path; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
@Getter | ||
@EqualsAndHashCode | ||
public class ExternalTable { | ||
@NonNull String name; | ||
@NonNull String formatName; | ||
@NonNull String basePath; | ||
@NonNull String dataPath; | ||
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. Clarification: is 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. Delta lake can also handle absolute paths so the metadata and data do not need to be under the same path. The data path is always set if you read through the constructor code below this. 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. The 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. Do you mean 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. Or do you mean that we only need to set a "target metadata path" in the 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. Iceberg table properties to control location of files include However, even though Delta supports absolute path for data files, Delta table properties ref do not seem to provide option to control the location of metadata files. Hudi also requires same table location prefix for both data and metadata, and does not seem to provide options to configure these at table level. As metadata location and data location do not apply to Hudi and Delta, I am wondering if the 3 properties should be part of the generic SourceTable config. The metadata and data locations could be confusing when the table format does not support it. We could document it clearly to avoid confusion. And that maybe better than creating format specific SourceTables (e.g. IcebergSourceTable). 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. I've moved the |
||
String[] namespace; | ||
CatalogConfig catalogConfig; | ||
|
||
ExternalTable( | ||
@NonNull String name, | ||
@NonNull String formatName, | ||
@NonNull String basePath, | ||
String dataPath, | ||
String[] namespace, | ||
CatalogConfig catalogConfig) { | ||
this.name = name; | ||
this.formatName = formatName; | ||
this.basePath = sanitizeBasePath(basePath); | ||
this.dataPath = dataPath == null ? this.basePath : sanitizeBasePath(dataPath); | ||
this.namespace = namespace; | ||
this.catalogConfig = catalogConfig; | ||
} | ||
|
||
private String sanitizeBasePath(String tableBasePath) { | ||
Path path = new Path(tableBasePath); | ||
Preconditions.checkArgument(path.isAbsolute(), "Table base path must be absolute"); | ||
if (path.isAbsoluteAndSchemeAuthorityNull()) { | ||
// assume this is local file system and append scheme | ||
return "file://" + path; | ||
} else if (path.toUri().getScheme().equals("file")) { | ||
// add extra slashes | ||
return "file://" + path.toUri().getPath(); | ||
} else { | ||
return path.toString(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 io.onetable.client; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@EqualsAndHashCode(callSuper = true) | ||
public class TargetTable extends ExternalTable { | ||
int metadataRetentionInHours; | ||
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. nit: add a javadoc. I wonder if using the 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. Makes sense, I've updated the type and will clean things up once this PR is in better shape |
||
|
||
@Builder(toBuilder = true) | ||
public TargetTable( | ||
String name, | ||
String formatName, | ||
String basePath, | ||
String dataPath, | ||
String[] namespace, | ||
CatalogConfig catalogConfig, | ||
Integer metadataRetentionInHours) { | ||
super(name, formatName, basePath, dataPath, namespace, catalogConfig); | ||
this.metadataRetentionInHours = | ||
metadataRetentionInHours == null ? 24 * 7 : metadataRetentionInHours; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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 io.onetable.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestSourceTable { | ||
@Test | ||
void sanitizePath() { | ||
SourceTable tooManySlashes = | ||
SourceTable.builder().basePath("s3://bucket//path").name("name").formatName("hudi").build(); | ||
assertEquals("s3://bucket/path", tooManySlashes.getBasePath()); | ||
|
||
SourceTable localFilePath = | ||
SourceTable.builder().basePath("/local/data//path").name("name").formatName("hudi").build(); | ||
assertEquals("file:///local/data/path", localFilePath.getBasePath()); | ||
|
||
SourceTable properLocalFilePath = | ||
SourceTable.builder() | ||
.basePath("file:///local/data//path") | ||
.name("name") | ||
.formatName("hudi") | ||
.build(); | ||
assertEquals("file:///local/data/path", properLocalFilePath.getBasePath()); | ||
} | ||
|
||
@Test | ||
void errorIfRequiredArgsNotSet() { | ||
assertThrows(NullPointerException.class, () -> SourceTable.builder().name("name").build()); | ||
|
||
assertThrows( | ||
NullPointerException.class, | ||
() -> SourceTable.builder().basePath("file://bucket/path").build()); | ||
|
||
assertThrows( | ||
NullPointerException.class, | ||
() -> SourceTable.builder().basePath("file://bucket/path").name("name").build()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 io.onetable.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestTargetTable { | ||
@Test | ||
void sanitizePath() { | ||
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. nit: The test in |
||
TargetTable tooManySlashes = | ||
TargetTable.builder().basePath("s3://bucket//path").name("name").formatName("hudi").build(); | ||
assertEquals("s3://bucket/path", tooManySlashes.getBasePath()); | ||
|
||
TargetTable localFilePath = | ||
TargetTable.builder().basePath("/local/data//path").name("name").formatName("hudi").build(); | ||
assertEquals("file:///local/data/path", localFilePath.getBasePath()); | ||
|
||
TargetTable properLocalFilePath = | ||
TargetTable.builder() | ||
.basePath("file:///local/data//path") | ||
.name("name") | ||
.formatName("hudi") | ||
.build(); | ||
assertEquals("file:///local/data/path", properLocalFilePath.getBasePath()); | ||
} | ||
|
||
@Test | ||
void defaultValueSet() { | ||
TargetTable table = | ||
TargetTable.builder() | ||
.basePath("file://bucket/path") | ||
.name("name") | ||
.formatName("hudi") | ||
.build(); | ||
|
||
assertEquals(24 * 7, table.getMetadataRetentionInHours()); | ||
assertNull(table.getNamespace()); | ||
assertNull(table.getCatalogConfig()); | ||
} | ||
|
||
@Test | ||
void errorIfRequiredArgsNotSet() { | ||
assertThrows(NullPointerException.class, () -> SourceTable.builder().name("name").build()); | ||
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. SourceTable? |
||
|
||
assertThrows( | ||
NullPointerException.class, | ||
() -> SourceTable.builder().basePath("file://bucket/path").build()); | ||
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. SourceTable? |
||
|
||
assertThrows( | ||
NullPointerException.class, | ||
() -> SourceTable.builder().basePath("file://bucket/path").name("name").build()); | ||
} | ||
} |
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.
nit: A javadoc comment for this member would clarify its purpose and avoid any confusion.
Suggestion:
basePath is the absolute addressable path of the table, which consists of the scheme, the namespace, and the table directories. For example, the basePath of a table, myTable, in ADLS in a namespace named myNamespace would be abfss://[email protected]/foo/bar/myNamespace/myTable