[go: nahoru, domu]

Skip to content

Commit

Permalink
Adds BigQuery Routines CRUD operations. * Fixes #3762
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-tarafa committed May 28, 2020
1 parent a4455b9 commit 8e9c40f
Show file tree
Hide file tree
Showing 31 changed files with 2,553 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ public class ApiMethod
private static readonly Parameter TableIdParameter = new Parameter("string", "tableId", "The table ID. Must not be null.", null);
private static readonly Parameter JobIdParameter = new Parameter("string", "jobId", "The job ID. Must not be null.", null);
private static readonly Parameter ModelIdParameter = new Parameter("string", "modelId", "The model ID. Must not be null.", null);
private static readonly Parameter RoutineIdParameter = new Parameter("string", "routineId", "The routine ID. Must not be null.", null);
private static readonly Parameter DatasetReferenceParameter = new Parameter("DatasetReference", "datasetReference", "A fully-qualified identifier for the dataset. Must not be null.", null);
private static readonly Parameter TableReferenceParameter = new Parameter("TableReference", "tableReference", "A fully-qualified identifier for the table. Must not be null.", null);
private static readonly Parameter JobReferenceParameter = new Parameter("JobReference", "jobReference", "A fully-qualified identifier for the job. Must not be null.", null);
private static readonly Parameter ProjectReferenceParameter = new Parameter("ProjectReference", "projectReference", "A fully-qualified identifier for the project. Must not be null.", null);
private static readonly Parameter ModelReferenceParameter = new Parameter("ModelReference", "modelReference", "A fully-qualified identifier for the model. Must not be null.", null);
private static readonly Parameter RoutineReferenceParameter = new Parameter("RoutineReference", "routineReference", "A fully-qualified identifier for the routine. Must not be null.", null);
private static readonly Parameter CancellationTokenParameter = new Parameter("CancellationToken", "cancellationToken", "The token to monitor for cancellation requests.", "default");

private static readonly Parameter[] IdParameters = { ProjectIdParameter, DatasetIdParameter, TableIdParameter, JobIdParameter, ModelIdParameter };
private static readonly Parameter[] IdParameters = { ProjectIdParameter, DatasetIdParameter, TableIdParameter, JobIdParameter, ModelIdParameter, RoutineIdParameter };

private static readonly Dictionary<TargetType, Parameter[]> TargetParametersByType = new Dictionary<TargetType, Parameter[]>
{
Expand All @@ -43,6 +45,7 @@ public class ApiMethod
{ TargetType.Job, new[] { ProjectIdParameter, JobIdParameter } },
{ TargetType.Project, new[] { ProjectIdParameter } },
{ TargetType.Model, new[] { ProjectIdParameter, DatasetIdParameter, ModelIdParameter } },
{ TargetType.Routine, new[] {ProjectIdParameter, DatasetIdParameter, RoutineIdParameter} },
{ TargetType.None, new Parameter[0] },
};

Expand All @@ -53,6 +56,7 @@ public class ApiMethod
{ TargetType.Job, JobReferenceParameter },
{ TargetType.Project, ProjectReferenceParameter },
{ TargetType.Model, ModelReferenceParameter },
{ TargetType.Routine, RoutineReferenceParameter },
{ TargetType.None, null },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>False</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<File>

<Method Name="GetRoutine"
TargetType="Routine"
ReturnType="BigQueryRoutine">
<Comments>
<summary>
Retrieves {target}.
</summary>
<returns>The requested routine.</returns>
</Comments>
</Method>

<Method Name="CreateRoutine"
TargetType="Routine"
ReturnType="BigQueryRoutine">
<AdditionalParameters>
<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." />
</AdditionalParameters>
<Comments>
<summary>
Creates {target}.
</summary>
<returns>The newly created routine.</returns>
</Comments>
</Method>

<Method Name="GetOrCreateRoutine"
TargetType="Routine"
ReturnType="BigQueryRoutine">
<AdditionalParameters>
<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." />
<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" />
</AdditionalParameters>
<Options Type="CreateRoutineOptions" Name="createOptions" Comment="The options for the &quot;create&quot; operation. May be null, in which case defaults will be supplied." />
<Comments>
<summary>
Attempts to fetch {target}, creating it if it doesn't exist.
</summary>
<returns>The existing or new routine.</returns>
</Comments>
</Method>

<Method Name="DeleteRoutine"
TargetType="Routine"
ReturnType="void">
<Comments>
<summary>
Deletes {target}.
</summary>
</Comments>
</Method>

<Method Name="UpdateRoutine"
TargetType="Routine"
ReturnType="BigQueryRoutine">
<AdditionalParameters>
<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." />
</AdditionalParameters>
<Comments>
<summary>
Updates {target} to match the specified resource.
</summary>
<remarks>
If the resource contains an ETag, it is used for optimistic concurrency validation.
</remarks>
<returns>The updated routine.</returns>
</Comments>
</Method>

</File>
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Text;

namespace Google.Cloud.BigQuery.V2.GenerateOverloads
{
public enum TargetType
Expand All @@ -25,6 +21,7 @@ public enum TargetType
Table,
Job,
Project,
Model
Model,
Routine
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ dotnet run -- Methods/InsertData.xml $CLIENT.InsertData.cs
dotnet run -- Methods/JobCrud.xml $CLIENT.JobCrud.cs
dotnet run -- Methods/ModelCrud.xml $CLIENT.ModelCrud.cs
dotnet run -- Methods/Queries.xml $CLIENT.Queries.cs
dotnet run -- Methods/TableCrud.xml $CLIENT.TableCrud.cs
dotnet run -- Methods/RoutineCrud.xml $CLIENT.RoutineCrud.cs
dotnet run -- Methods/ServiceAccount.xml $CLIENT.ServiceAccount.cs
dotnet run -- Methods/TableCrud.xml $CLIENT.TableCrud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class BigQueryFixture : CloudProjectFixtureBase, ICollectionFixture<BigQu
public string PeopleTableId { get; } = "people";
public string ComplexTypesTableId { get; } = "complex";
public string ExhaustiveTypesTableId { get; } = "exhaustive";

/// <summary>
/// A GCS bucket created for this fixture.
/// </summary>
Expand Down Expand Up @@ -263,6 +264,19 @@ private void CreateExhaustiveTypesTable(BigQueryDataset dataset)
InsertAndWait(table, () => table.InsertRow(ExhaustiveTypesTest.GetSampleRow()), 1);
}

internal void CreateRoutine(string routineId, BigQueryDataset dataset)
{
Routine routine = new Routine
{
DefinitionBody = "SELECT 1;",
Description = "test routine",
};
routine.SetRoutineLanguage(RoutineLanguage.Sql);
routine.SetRoutineType(RoutineType.StoredProcedure);

dataset.CreateRoutine(routineId, routine);
}

internal BigQueryInsertResults InsertAndWait(BigQueryTable table, Func<BigQueryInsertResults> insertAction, int expectedRowCountChange)
{
var countBefore = table.ListRows().Count();
Expand Down Expand Up @@ -294,6 +308,7 @@ internal List<string> LoadTextResource(string relativeName)

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

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

0 comments on commit 8e9c40f

Please sign in to comment.