-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: View core parser implementations
Co-authored-by: John Zhuge <[email protected]>
- Loading branch information
1 parent
d485cc8
commit 1be161b
Showing
16 changed files
with
1,341 additions
and
189 deletions.
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
206 changes: 206 additions & 0 deletions
206
core/src/main/java/org/apache/iceberg/view/BaseSQLViewRepresentation.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,206 @@ | ||
/* | ||
* 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.iceberg.view; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.apache.iceberg.catalog.Namespace; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
|
||
public class BaseSQLViewRepresentation implements SQLViewRepresentation { | ||
|
||
private final String query; | ||
private final String dialect; | ||
private final String defaultCatalog; | ||
private final int schemaId; | ||
private final Namespace defaultNamespace; | ||
private final List<String> fieldAliases; | ||
private final List<String> fieldComments; | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static Builder buildFrom(SQLViewRepresentation representation) { | ||
return builder() | ||
.query(representation.query()) | ||
.schemaId(representation.schemaId()) | ||
.dialect(representation.dialect()) | ||
.defaultCatalog(representation.defaultCatalog()) | ||
.defaultNamespace(representation.defaultNamespace()) | ||
.fieldAliases(representation.fieldAliases()) | ||
.fieldComments(representation.fieldComments()); | ||
} | ||
|
||
private BaseSQLViewRepresentation( | ||
String query, | ||
String dialect, | ||
String defaultCatalog, | ||
Namespace defaultNamespace, | ||
int schemaId, | ||
List<String> fieldAliases, | ||
List<String> fieldComments) { | ||
this.query = Preconditions.checkNotNull(query, "sql should not be null"); | ||
this.dialect = Preconditions.checkNotNull(dialect, "dialect should not be null"); | ||
this.defaultCatalog = | ||
Preconditions.checkNotNull(defaultCatalog, "default catalog should not null"); | ||
this.defaultNamespace = | ||
Preconditions.checkNotNull(defaultNamespace, "default namespace should not be null"); | ||
this.schemaId = Preconditions.checkNotNull(schemaId, "schema should not be null"); | ||
this.fieldAliases = | ||
Preconditions.checkNotNull(fieldAliases, "field aliases should not be null"); | ||
this.fieldComments = | ||
Preconditions.checkNotNull(fieldComments, "field comments should not be null"); | ||
} | ||
|
||
@Override | ||
public String query() { | ||
return query; | ||
} | ||
|
||
@Override | ||
public String dialect() { | ||
return dialect; | ||
} | ||
|
||
@Override | ||
public String defaultCatalog() { | ||
return defaultCatalog; | ||
} | ||
|
||
@Override | ||
public Namespace defaultNamespace() { | ||
return defaultNamespace; | ||
} | ||
|
||
@Override | ||
public int schemaId() { | ||
return schemaId; | ||
} | ||
|
||
@Override | ||
public List<String> fieldComments() { | ||
return fieldComments; | ||
} | ||
|
||
@Override | ||
public List<String> fieldAliases() { | ||
return fieldAliases; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
BaseSQLViewRepresentation that = (BaseSQLViewRepresentation) o; | ||
return Objects.equals(query, that.query) | ||
&& Objects.equals(dialect, that.dialect) | ||
&& Objects.equals(schemaId, that.schemaId) | ||
&& Objects.equals(defaultCatalog, that.defaultCatalog) | ||
&& Objects.equals(defaultNamespace, that.defaultNamespace) | ||
&& Objects.equals(fieldAliases, that.fieldAliases) | ||
&& Objects.equals(fieldComments, that.fieldComments); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash( | ||
query, dialect, schemaId, defaultCatalog, defaultNamespace, fieldAliases, fieldComments); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BaseViewDefinition{" | ||
+ "query='" | ||
+ query | ||
+ '\'' | ||
+ ", dialect=" | ||
+ dialect | ||
+ ", schema=" | ||
+ schemaId | ||
+ ", defaultCatalog='" | ||
+ defaultCatalog | ||
+ '\'' | ||
+ ", defaultNamespace=" | ||
+ defaultNamespace | ||
+ ", fieldAliases=" | ||
+ fieldAliases | ||
+ ", fieldComments=" | ||
+ fieldComments | ||
+ '}'; | ||
} | ||
|
||
public static final class Builder { | ||
|
||
private String sql; | ||
private int schemaId; | ||
private String dialect = ""; | ||
private String defaultCatalog = ""; | ||
private Namespace defaultNamespace = Namespace.empty(); | ||
private List<String> fieldAliases = Collections.emptyList(); | ||
private List<String> fieldComments = Collections.emptyList(); | ||
|
||
private Builder() {} | ||
|
||
public Builder query(String value) { | ||
sql = value; | ||
return this; | ||
} | ||
|
||
public Builder dialect(String value) { | ||
dialect = value; | ||
return this; | ||
} | ||
|
||
public Builder schemaId(int value) { | ||
schemaId = value; | ||
return this; | ||
} | ||
|
||
public Builder defaultCatalog(String value) { | ||
defaultCatalog = value; | ||
return this; | ||
} | ||
|
||
public Builder defaultNamespace(Namespace value) { | ||
defaultNamespace = value; | ||
return this; | ||
} | ||
|
||
public Builder fieldAliases(List<String> value) { | ||
fieldAliases = value; | ||
return this; | ||
} | ||
|
||
public Builder fieldComments(List<String> value) { | ||
fieldComments = value; | ||
return this; | ||
} | ||
|
||
public BaseSQLViewRepresentation build() { | ||
return new BaseSQLViewRepresentation( | ||
sql, dialect, defaultCatalog, defaultNamespace, schemaId, fieldAliases, fieldComments); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
core/src/main/java/org/apache/iceberg/view/BaseViewHistoryEntry.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,71 @@ | ||
/* | ||
* 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.iceberg.view; | ||
|
||
import java.util.Objects; | ||
import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; | ||
|
||
public class BaseViewHistoryEntry implements ViewHistoryEntry { | ||
private final long timestampMillis; | ||
private final int versionId; | ||
|
||
static ViewHistoryEntry of(long timestampMillis, int versionId) { | ||
return new BaseViewHistoryEntry(timestampMillis, versionId); | ||
} | ||
|
||
private BaseViewHistoryEntry(long timestampMillis, int versionId) { | ||
this.timestampMillis = timestampMillis; | ||
this.versionId = versionId; | ||
} | ||
|
||
@Override | ||
public long timestampMillis() { | ||
return timestampMillis; | ||
} | ||
|
||
@Override | ||
public int versionId() { | ||
return versionId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
BaseViewHistoryEntry that = (BaseViewHistoryEntry) other; | ||
return timestampMillis == that.timestampMillis && versionId == that.versionId; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(timestampMillis, versionId); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("timestampMillis", timestampMillis) | ||
.add("versionId", versionId) | ||
.toString(); | ||
} | ||
} |
Oops, something went wrong.