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
feat: add support for partitioning and clustering in MaterializedViewDefinition #1301
Changes from 1 commit
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 |
---|---|---|
|
@@ -57,6 +57,24 @@ public abstract static class Builder | |
@Override | ||
public abstract Builder setType(Type type); | ||
|
||
/** | ||
* Sets the time partitioning configuration for the table. If not set, the table is not | ||
* time-partitioned. | ||
*/ | ||
public abstract Builder setTimePartitioning(TimePartitioning timePartitioning); | ||
|
||
/** | ||
* Sets the range partitioning configuration for the table. Only one of timePartitioning and | ||
* rangePartitioning should be specified. | ||
*/ | ||
public abstract Builder setRangePartitioning(RangePartitioning rangePartitioning); | ||
|
||
/** | ||
* Set the clustering configuration for the table. If not set, the table is not clustered. | ||
* BigQuery supports clustering for both partitioned and non-partitioned tables. | ||
*/ | ||
public abstract Builder setClustering(Clustering clustering); | ||
|
||
/** Creates a {@code MaterializedViewDefinition} object. */ | ||
@Override | ||
public abstract MaterializedViewDefinition build(); | ||
|
@@ -86,6 +104,27 @@ public abstract static class Builder | |
@Nullable | ||
public abstract Long getRefreshIntervalMs(); | ||
|
||
/** | ||
* Returns the time partitioning configuration for this table. If {@code null}, the table is not | ||
* time-partitioned. | ||
*/ | ||
@Nullable | ||
public abstract TimePartitioning getTimePartitioning(); | ||
|
||
/** | ||
* Returns the range partitioning configuration for this table. If {@code null}, the table is not | ||
* range-partitioned. | ||
*/ | ||
@Nullable | ||
public abstract RangePartitioning getRangePartitioning(); | ||
|
||
/** | ||
* Returns the clustering configuration for this table. If {@code null}, the table is not | ||
* clustered. | ||
*/ | ||
@Nullable | ||
public abstract Clustering getClustering(); | ||
|
||
/** Returns a builder for the {@code MaterializedViewDefinition} object. */ | ||
public abstract Builder toBuilder(); | ||
|
||
|
@@ -107,6 +146,15 @@ Table toPb() { | |
materializedViewDefinition.setRefreshIntervalMs(getRefreshIntervalMs()); | ||
} | ||
tablePb.setMaterializedView(materializedViewDefinition); | ||
if (getTimePartitioning() != null) { | ||
tablePb.setTimePartitioning(getTimePartitioning().toPb()); | ||
} | ||
if (getRangePartitioning() != null) { | ||
tablePb.setRangePartitioning(getRangePartitioning().toPb()); | ||
} | ||
if (getClustering() != null) { | ||
tablePb.setClustering(getClustering().toPb()); | ||
} | ||
return tablePb; | ||
} | ||
|
||
|
@@ -149,6 +197,28 @@ static MaterializedViewDefinition fromPb(Table tablePb) { | |
if (materializedViewDefinition.getRefreshIntervalMs() != null) { | ||
builder.setRefreshIntervalMs(materializedViewDefinition.getRefreshIntervalMs()); | ||
} | ||
if (tablePb.getTimePartitioning() != null) { | ||
try { | ||
builder.setTimePartitioning(TimePartitioning.fromPb(tablePb.getTimePartitioning())); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException( | ||
"Illegal Argument - Got unexpected time partitioning " | ||
+ tablePb.getTimePartitioning().getType() | ||
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 want to intercept like this? Seems like we may want the other fromPb() message functions to be responsible for throwing a human readable error? 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. Okay - I removed this interception. |
||
+ " in project " | ||
+ tablePb.getTableReference().getProjectId() | ||
+ " in dataset " | ||
+ tablePb.getTableReference().getDatasetId() | ||
+ " in table " | ||
+ tablePb.getTableReference().getTableId(), | ||
e); | ||
} | ||
} | ||
if (tablePb.getRangePartitioning() != null) { | ||
builder.setRangePartitioning(RangePartitioning.fromPb(tablePb.getRangePartitioning())); | ||
} | ||
if (tablePb.getClustering() != null) { | ||
builder.setClustering(Clustering.fromPb(tablePb.getClustering())); | ||
} | ||
} | ||
return builder.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: do we want to update the comments here and elsewhere to indicate materialized view, rather than table?
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.
Yes -- Updated to
materialized view
.