@@ -57,6 +57,24 @@ public abstract static class Builder
5757 @ Override
5858 public abstract Builder setType (Type type );
5959
60+ /**
61+ * Sets the time partitioning configuration for the table. If not set, the table is not
62+ * time-partitioned.
63+ */
64+ public abstract Builder setTimePartitioning (TimePartitioning timePartitioning );
65+
66+ /**
67+ * Sets the range partitioning configuration for the table. Only one of timePartitioning and
68+ * rangePartitioning should be specified.
69+ */
70+ public abstract Builder setRangePartitioning (RangePartitioning rangePartitioning );
71+
72+ /**
73+ * Set the clustering configuration for the table. If not set, the table is not clustered.
74+ * BigQuery supports clustering for both partitioned and non-partitioned tables.
75+ */
76+ public abstract Builder setClustering (Clustering clustering );
77+
6078 /** Creates a {@code MaterializedViewDefinition} object. */
6179 @ Override
6280 public abstract MaterializedViewDefinition build ();
@@ -86,6 +104,27 @@ public abstract static class Builder
86104 @ Nullable
87105 public abstract Long getRefreshIntervalMs ();
88106
107+ /**
108+ * Returns the time partitioning configuration for this table. If {@code null}, the table is not
109+ * time-partitioned.
110+ */
111+ @ Nullable
112+ public abstract TimePartitioning getTimePartitioning ();
113+
114+ /**
115+ * Returns the range partitioning configuration for this table. If {@code null}, the table is not
116+ * range-partitioned.
117+ */
118+ @ Nullable
119+ public abstract RangePartitioning getRangePartitioning ();
120+
121+ /**
122+ * Returns the clustering configuration for this table. If {@code null}, the table is not
123+ * clustered.
124+ */
125+ @ Nullable
126+ public abstract Clustering getClustering ();
127+
89128 /** Returns a builder for the {@code MaterializedViewDefinition} object. */
90129 public abstract Builder toBuilder ();
91130
@@ -107,6 +146,15 @@ Table toPb() {
107146 materializedViewDefinition .setRefreshIntervalMs (getRefreshIntervalMs ());
108147 }
109148 tablePb .setMaterializedView (materializedViewDefinition );
149+ if (getTimePartitioning () != null ) {
150+ tablePb .setTimePartitioning (getTimePartitioning ().toPb ());
151+ }
152+ if (getRangePartitioning () != null ) {
153+ tablePb .setRangePartitioning (getRangePartitioning ().toPb ());
154+ }
155+ if (getClustering () != null ) {
156+ tablePb .setClustering (getClustering ().toPb ());
157+ }
110158 return tablePb ;
111159 }
112160
@@ -149,6 +197,28 @@ static MaterializedViewDefinition fromPb(Table tablePb) {
149197 if (materializedViewDefinition .getRefreshIntervalMs () != null ) {
150198 builder .setRefreshIntervalMs (materializedViewDefinition .getRefreshIntervalMs ());
151199 }
200+ if (tablePb .getTimePartitioning () != null ) {
201+ try {
202+ builder .setTimePartitioning (TimePartitioning .fromPb (tablePb .getTimePartitioning ()));
203+ } catch (IllegalArgumentException e ) {
204+ throw new IllegalArgumentException (
205+ "Illegal Argument - Got unexpected time partitioning "
206+ + tablePb .getTimePartitioning ().getType ()
207+ + " in project "
208+ + tablePb .getTableReference ().getProjectId ()
209+ + " in dataset "
210+ + tablePb .getTableReference ().getDatasetId ()
211+ + " in table "
212+ + tablePb .getTableReference ().getTableId (),
213+ e );
214+ }
215+ }
216+ if (tablePb .getRangePartitioning () != null ) {
217+ builder .setRangePartitioning (RangePartitioning .fromPb (tablePb .getRangePartitioning ()));
218+ }
219+ if (tablePb .getClustering () != null ) {
220+ builder .setClustering (Clustering .fromPb (tablePb .getClustering ()));
221+ }
152222 }
153223 return builder .build ();
154224 }
0 commit comments