Skip to content

Commit 8e9c40f

Browse files
committed
Adds BigQuery Routines CRUD operations. * Fixes #3762
1 parent a4455b9 commit 8e9c40f

31 files changed

+2553
-12
lines changed

apis/Google.Cloud.BigQuery.V2/Google.Cloud.BigQuery.V2.GenerateOverloads/ApiMethod.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ public class ApiMethod
2727
private static readonly Parameter TableIdParameter = new Parameter("string", "tableId", "The table ID. Must not be null.", null);
2828
private static readonly Parameter JobIdParameter = new Parameter("string", "jobId", "The job ID. Must not be null.", null);
2929
private static readonly Parameter ModelIdParameter = new Parameter("string", "modelId", "The model ID. Must not be null.", null);
30+
private static readonly Parameter RoutineIdParameter = new Parameter("string", "routineId", "The routine ID. Must not be null.", null);
3031
private static readonly Parameter DatasetReferenceParameter = new Parameter("DatasetReference", "datasetReference", "A fully-qualified identifier for the dataset. Must not be null.", null);
3132
private static readonly Parameter TableReferenceParameter = new Parameter("TableReference", "tableReference", "A fully-qualified identifier for the table. Must not be null.", null);
3233
private static readonly Parameter JobReferenceParameter = new Parameter("JobReference", "jobReference", "A fully-qualified identifier for the job. Must not be null.", null);
3334
private static readonly Parameter ProjectReferenceParameter = new Parameter("ProjectReference", "projectReference", "A fully-qualified identifier for the project. Must not be null.", null);
3435
private static readonly Parameter ModelReferenceParameter = new Parameter("ModelReference", "modelReference", "A fully-qualified identifier for the model. Must not be null.", null);
36+
private static readonly Parameter RoutineReferenceParameter = new Parameter("RoutineReference", "routineReference", "A fully-qualified identifier for the routine. Must not be null.", null);
3537
private static readonly Parameter CancellationTokenParameter = new Parameter("CancellationToken", "cancellationToken", "The token to monitor for cancellation requests.", "default");
3638

37-
private static readonly Parameter[] IdParameters = { ProjectIdParameter, DatasetIdParameter, TableIdParameter, JobIdParameter, ModelIdParameter };
39+
private static readonly Parameter[] IdParameters = { ProjectIdParameter, DatasetIdParameter, TableIdParameter, JobIdParameter, ModelIdParameter, RoutineIdParameter };
3840

3941
private static readonly Dictionary<TargetType, Parameter[]> TargetParametersByType = new Dictionary<TargetType, Parameter[]>
4042
{
@@ -43,6 +45,7 @@ public class ApiMethod
4345
{ TargetType.Job, new[] { ProjectIdParameter, JobIdParameter } },
4446
{ TargetType.Project, new[] { ProjectIdParameter } },
4547
{ TargetType.Model, new[] { ProjectIdParameter, DatasetIdParameter, ModelIdParameter } },
48+
{ TargetType.Routine, new[] {ProjectIdParameter, DatasetIdParameter, RoutineIdParameter} },
4649
{ TargetType.None, new Parameter[0] },
4750
};
4851

@@ -53,6 +56,7 @@ public class ApiMethod
5356
{ TargetType.Job, JobReferenceParameter },
5457
{ TargetType.Project, ProjectReferenceParameter },
5558
{ TargetType.Model, ModelReferenceParameter },
59+
{ TargetType.Routine, RoutineReferenceParameter },
5660
{ TargetType.None, null },
5761
};
5862

apis/Google.Cloud.BigQuery.V2/Google.Cloud.BigQuery.V2.GenerateOverloads/Google.Cloud.BigQuery.V2.GenerateOverloads.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp1.0</TargetFramework>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<IsPackable>False</IsPackable>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
88
</PropertyGroup>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<File>
2+
3+
<Method Name="GetRoutine"
4+
TargetType="Routine"
5+
ReturnType="BigQueryRoutine">
6+
<Comments>
7+
<summary>
8+
Retrieves {target}.
9+
</summary>
10+
<returns>The requested routine.</returns>
11+
</Comments>
12+
</Method>
13+
14+
<Method Name="CreateRoutine"
15+
TargetType="Routine"
16+
ReturnType="BigQueryRoutine">
17+
<AdditionalParameters>
18+
<Parameter Name="resource" Type="Routine" Comment="The routine resource representation to use for the creation. Must not be null. If this routine's &lt;see cref=&quot;Routine.RoutineReference&quot;/&gt; is specified, then it must be the same as the one obtained from the other parameters, else it will be set to the one obtained from the other parameters." />
19+
</AdditionalParameters>
20+
<Comments>
21+
<summary>
22+
Creates {target}.
23+
</summary>
24+
<returns>The newly created routine.</returns>
25+
</Comments>
26+
</Method>
27+
28+
<Method Name="GetOrCreateRoutine"
29+
TargetType="Routine"
30+
ReturnType="BigQueryRoutine">
31+
<AdditionalParameters>
32+
<Parameter Name="resource" Type="Routine" Comment="The routine resource representation to use for the creation. Must not be null. If this routine's &lt;see cref=&quot;Routine.RoutineReference&quot;/&gt; is specified, then it must be the same as the one obtained from the other parameters, else it will be set to the one obtained from the other parameters." />
33+
<Parameter Type="GetRoutineOptions" Name="getOptions" Comment="The options for the &quot;get&quot; operation. May be null, in which case defaults will be supplied." DefaultValue="null" />
34+
</AdditionalParameters>
35+
<Options Type="CreateRoutineOptions" Name="createOptions" Comment="The options for the &quot;create&quot; operation. May be null, in which case defaults will be supplied." />
36+
<Comments>
37+
<summary>
38+
Attempts to fetch {target}, creating it if it doesn't exist.
39+
</summary>
40+
<returns>The existing or new routine.</returns>
41+
</Comments>
42+
</Method>
43+
44+
<Method Name="DeleteRoutine"
45+
TargetType="Routine"
46+
ReturnType="void">
47+
<Comments>
48+
<summary>
49+
Deletes {target}.
50+
</summary>
51+
</Comments>
52+
</Method>
53+
54+
<Method Name="UpdateRoutine"
55+
TargetType="Routine"
56+
ReturnType="BigQueryRoutine">
57+
<AdditionalParameters>
58+
<Parameter Name="resource" Type="Routine" Comment="The routine resource representation to use for the update. All updatable fields will be updated. If this routine's &lt;see cref=&quot;Routine.RoutineReference&quot;/&gt; is specified, then it must be the same as the one obtained from the other parameters, else it will be set to the one obtained from the other parameters." />
59+
</AdditionalParameters>
60+
<Comments>
61+
<summary>
62+
Updates {target} to match the specified resource.
63+
</summary>
64+
<remarks>
65+
If the resource contains an ETag, it is used for optimistic concurrency validation.
66+
</remarks>
67+
<returns>The updated routine.</returns>
68+
</Comments>
69+
</Method>
70+
71+
</File>

apis/Google.Cloud.BigQuery.V2/Google.Cloud.BigQuery.V2.GenerateOverloads/TargetType.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using System;
16-
using System.Collections.Generic;
17-
using System.Text;
18-
1915
namespace Google.Cloud.BigQuery.V2.GenerateOverloads
2016
{
2117
public enum TargetType
@@ -25,6 +21,7 @@ public enum TargetType
2521
Table,
2622
Job,
2723
Project,
28-
Model
24+
Model,
25+
Routine
2926
}
3027
}

apis/Google.Cloud.BigQuery.V2/Google.Cloud.BigQuery.V2.GenerateOverloads/generateoverloads.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ dotnet run -- Methods/InsertData.xml $CLIENT.InsertData.cs
88
dotnet run -- Methods/JobCrud.xml $CLIENT.JobCrud.cs
99
dotnet run -- Methods/ModelCrud.xml $CLIENT.ModelCrud.cs
1010
dotnet run -- Methods/Queries.xml $CLIENT.Queries.cs
11-
dotnet run -- Methods/TableCrud.xml $CLIENT.TableCrud.cs
11+
dotnet run -- Methods/RoutineCrud.xml $CLIENT.RoutineCrud.cs
1212
dotnet run -- Methods/ServiceAccount.xml $CLIENT.ServiceAccount.cs
13+
dotnet run -- Methods/TableCrud.xml $CLIENT.TableCrud.cs

apis/Google.Cloud.BigQuery.V2/Google.Cloud.BigQuery.V2.IntegrationTests/BigQueryFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class BigQueryFixture : CloudProjectFixtureBase, ICollectionFixture<BigQu
4949
public string PeopleTableId { get; } = "people";
5050
public string ComplexTypesTableId { get; } = "complex";
5151
public string ExhaustiveTypesTableId { get; } = "exhaustive";
52+
5253
/// <summary>
5354
/// A GCS bucket created for this fixture.
5455
/// </summary>
@@ -263,6 +264,19 @@ private void CreateExhaustiveTypesTable(BigQueryDataset dataset)
263264
InsertAndWait(table, () => table.InsertRow(ExhaustiveTypesTest.GetSampleRow()), 1);
264265
}
265266

267+
internal void CreateRoutine(string routineId, BigQueryDataset dataset)
268+
{
269+
Routine routine = new Routine
270+
{
271+
DefinitionBody = "SELECT 1;",
272+
Description = "test routine",
273+
};
274+
routine.SetRoutineLanguage(RoutineLanguage.Sql);
275+
routine.SetRoutineType(RoutineType.StoredProcedure);
276+
277+
dataset.CreateRoutine(routineId, routine);
278+
}
279+
266280
internal BigQueryInsertResults InsertAndWait(BigQueryTable table, Func<BigQueryInsertResults> insertAction, int expectedRowCountChange)
267281
{
268282
var countBefore = table.ListRows().Count();
@@ -294,6 +308,7 @@ internal List<string> LoadTextResource(string relativeName)
294308

295309
internal string CreateTableId() => IdGenerator.FromGuid(prefix: "test_", separator: "_");
296310
internal string CreateDatasetId() => $"{DatasetId}_{Interlocked.Increment(ref extraDatasetCounter)}";
311+
internal string CreateRoutineId() => IdGenerator.FromGuid(prefix: "test_", separator: "_");
297312

298313
/// <summary>
299314
/// Sets the labels on <see cref="LabelsDatasetId"/> without using any of the client *Labels methods.

0 commit comments

Comments
 (0)