public void USqlBuildTest() { using (var context = MockContext.Start(this.GetType())) { commonData = new CommonTestFixture(context); commonData.HostUrl = commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount( commonData.ResourceGroupName, commonData.Location, commonData.DataLakeStoreAccountName, commonData.SecondDataLakeAnalyticsAccountName ); // Wait 5 minutes for the account setup TestUtilities.Wait(300000); var clientToUse = this.GetDataLakeAnalyticsJobManagementClient(context); // Compile a usql job, which requires a jobId in the job object // Submit a usql job to the account var jobToBuild = new BuildJobParameters { Name = "azure sdk data lake analytics job", Type = JobType.USql, Properties = new CreateUSqlJobProperties { Script = "DROP DATABASE IF EXISTS testdb; CREATE DATABASE testdb;" } }; // Just compile the usql job, which requires a jobId in the job object var compileResponse = clientToUse.Job.Build( commonData.SecondDataLakeAnalyticsAccountName, jobToBuild ); Assert.NotNull(compileResponse); // Now compile a broken usql job and verify diagnostics report an error jobToBuild.Properties.Script = "DROP DATABASE IF EXIST FOO; CREATE DATABASE FOO;"; compileResponse = clientToUse.Job.Build( commonData.SecondDataLakeAnalyticsAccountName, jobToBuild ); Assert.NotNull(compileResponse); Assert.Equal(1, ((USqlJobProperties)compileResponse.Properties).Diagnostics.Count); Assert.Equal(SeverityTypes.Error, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Severity); Assert.Equal(18, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].ColumnNumber); Assert.Equal(22, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].End); Assert.Equal(17, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Start); Assert.Equal(1, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].LineNumber); Assert.Contains("E_CSC_USER_SYNTAXERROR", ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Message); } }
public JobInformationBasicEx BuildJob(JobCreateParameters parameters) { FixupCreateJobParameters(parameters); var cj = new CreateJobProperties(parameters.ScriptText, null); var bj_parameters = new BuildJobParameters(JobType.USql, cj, parameters.JobName); var job_info = this.RestClients.JobsClient.Job.Build(this.Account.Name, bj_parameters); var j = new JobInformationBasicEx(job_info, this.Account); return(j); }
/// <summary> /// Builds (compiles) the specified job in the specified Data Lake Analytics /// account for job correctness and validation. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='accountName'> /// The Azure Data Lake Analytics account to execute job operations on. /// </param> /// <param name='parameters'> /// The parameters to build a job. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <JobInformation> BuildAsync(this IJobOperations operations, string accountName, BuildJobParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BuildWithHttpMessagesAsync(accountName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Builds (compiles) the specified job in the specified Data Lake Analytics /// account for job correctness and validation. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='accountName'> /// The Azure Data Lake Analytics account to execute job operations on. /// </param> /// <param name='parameters'> /// The parameters to build a job. /// </param> public static JobInformation Build(this IJobOperations operations, string accountName, BuildJobParameters parameters) { return(operations.BuildAsync(accountName, parameters).GetAwaiter().GetResult()); }
public override void ExecuteCmdlet() { if (AnalyticsUnits < 1) { WriteWarning(Resources.InvalidAnalyticsUnits); } // Error handling for not passing or passing both script and script path if ((string.IsNullOrEmpty(Script) && string.IsNullOrEmpty(ScriptPath)) || (!string.IsNullOrEmpty(Script) && !string.IsNullOrEmpty(ScriptPath))) { throw new CloudException(Resources.AmbiguousScriptParameter); } // Get the script if (string.IsNullOrEmpty(Script)) { var powerShellDestinationPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(ScriptPath); if (!File.Exists(powerShellDestinationPath)) { throw new CloudException(string.Format(Resources.ScriptFilePathDoesNotExist, powerShellDestinationPath)); } Script = File.ReadAllText(powerShellDestinationPath); } // Check for script parameters if (ScriptParameter != null) { StringBuilder paramBuilder = new StringBuilder(); string paramVar = null; string paramValue = null; Type paramType = null; // Build the parameter string in order to prepend it to the script foreach (DictionaryEntry param in ScriptParameter) { if (param.Value == null) { throw new CloudException(string.Format(Resources.ScriptParameterValueIsNull, param.Key.ToString())); } paramVar = param.Key.ToString(); paramValue = param.Value.ToString(); paramType = param.Value.GetType(); if (paramType.Equals(typeof(byte))) { paramBuilder.Append(string.Format("DECLARE @{0} byte = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(sbyte))) { paramBuilder.Append(string.Format("DECLARE @{0} sbyte = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(int))) { paramBuilder.Append(string.Format("DECLARE @{0} int = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(uint))) { paramBuilder.Append(string.Format("DECLARE @{0} uint = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(long))) { paramBuilder.Append(string.Format("DECLARE @{0} long = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(ulong))) { paramBuilder.Append(string.Format("DECLARE @{0} ulong = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(float))) { paramBuilder.Append(string.Format("DECLARE @{0} float = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(double))) { paramBuilder.Append(string.Format("DECLARE @{0} double = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(decimal))) { paramBuilder.Append(string.Format("DECLARE @{0} decimal = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(short))) { paramBuilder.Append(string.Format("DECLARE @{0} short = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(ushort))) { paramBuilder.Append(string.Format("DECLARE @{0} ushort = {1};\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(char))) { paramBuilder.Append(string.Format("DECLARE @{0} char = '{1}';\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(string))) { paramBuilder.Append(string.Format("DECLARE @{0} string = \"{1}\";\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(DateTime))) { DateTime datetime = (DateTime)param.Value; paramBuilder.Append(string.Format("DECLARE @{0} DateTime = new DateTime({1}, {2}, {3}, {4}, {5}, {6}, {7});\n", paramVar, datetime.Year, datetime.Month, datetime.Day, datetime.Hour, datetime.Minute, datetime.Second, datetime.Millisecond)); } else if (paramType.Equals(typeof(bool))) { if ((bool)param.Value) { paramBuilder.Append(string.Format("DECLARE @{0} bool = true;\n", paramVar)); } else { paramBuilder.Append(string.Format("DECLARE @{0} bool = false;\n", paramVar)); } } else if (paramType.Equals(typeof(Guid))) { paramBuilder.Append(string.Format("DECLARE @{0} Guid = new Guid(\"{1}\");\n", paramVar, paramValue)); } else if (paramType.Equals(typeof(byte[]))) { StringBuilder byteArrayBuilder = new StringBuilder(string.Format("DECLARE @{0} byte[] = new byte[] {{", paramVar)); byte[] byteArray = (byte[])param.Value; if (byteArray.Length > 0) { foreach (byte b in byteArray) { byteArrayBuilder.Append(string.Format("\n {0},", b.ToString())); } byteArrayBuilder.Append("\n};\n"); } else { byteArrayBuilder.Append(" };\n"); } paramBuilder.Append(byteArrayBuilder.ToString()); } else { throw new CloudException(string.Format(Resources.InvalidScriptParameterType, paramType.ToString())); } } Script = Script.Insert(0, paramBuilder.ToString()); } JobType jobType; CreateJobProperties properties; if (USql) { jobType = JobType.USql; var sqlIpProperties = new CreateUSqlJobProperties { Script = Script }; if (!string.IsNullOrEmpty(CompileMode)) { CompileMode toUse; if (Enum.TryParse(CompileMode, out toUse)) { sqlIpProperties.CompileMode = toUse; } } if (!string.IsNullOrEmpty(Runtime)) { sqlIpProperties.RuntimeVersion = Runtime; } properties = sqlIpProperties; } else { throw new CloudException(Resources.InvalidJobType); } if (CompileOnly) { var buildJobParameters = new BuildJobParameters { Type = jobType, Name = Name, Properties = properties }; WriteObject(DataLakeAnalyticsClient.BuildJob(Account, buildJobParameters)); } else { var jobId = DataLakeAnalyticsClient.JobIdQueue.Count == 0 ? Guid.NewGuid() : DataLakeAnalyticsClient.JobIdQueue.Dequeue(); var createJobParameters = new CreateJobParameters { Type = jobType, Name = Name, DegreeOfParallelism = AnalyticsUnits, Priority = Priority, Properties = properties, }; if (ParameterSetName.Equals(USqlJobParameterSetNameAndRecurrence) || ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) || ParameterSetName.Equals(USqlJobWithScriptPathAndRecurrence) || ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline)) { createJobParameters.Related = new JobRelationshipProperties { RecurrenceId = RecurrenceId, RecurrenceName = RecurrenceName }; if (ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) || ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline)) { createJobParameters.Related.PipelineId = PipelineId; createJobParameters.Related.PipelineName = PipelineName; createJobParameters.Related.PipelineUri = PipelineUri; createJobParameters.Related.RunId = RunId; } } WriteObject(DataLakeAnalyticsClient.SubmitJob(Account, jobId, createJobParameters)); } }
public override void ExecuteCmdlet() { if (DegreeOfParallelism < 1) { WriteWarning(Resources.InvalidDegreeOfParallelism); } // error handling for not passing or passing both script and script path if ((string.IsNullOrEmpty(Script) && string.IsNullOrEmpty(ScriptPath)) || (!string.IsNullOrEmpty(Script) && !string.IsNullOrEmpty(ScriptPath))) { throw new CloudException(Resources.AmbiguousScriptParameter); } // get the script if (string.IsNullOrEmpty(Script)) { var powerShellDestinationPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(ScriptPath); if (!File.Exists(powerShellDestinationPath)) { throw new CloudException(string.Format(Resources.ScriptFilePathDoesNotExist, powerShellDestinationPath)); } Script = File.ReadAllText(powerShellDestinationPath); } JobType jobType; CreateJobProperties properties; if (USql) { jobType = JobType.USql; var sqlIpProperties = new CreateUSqlJobProperties { Script = Script }; if (!string.IsNullOrEmpty(CompileMode)) { CompileMode toUse; if (Enum.TryParse(CompileMode, out toUse)) { sqlIpProperties.CompileMode = toUse; } } if (!string.IsNullOrEmpty(Runtime)) { sqlIpProperties.RuntimeVersion = Runtime; } properties = sqlIpProperties; } else { throw new CloudException(Resources.InvalidJobType); } if (CompileOnly) { var buildJobParameters = new BuildJobParameters { Type = jobType, Name = Name, Properties = properties }; WriteObject(DataLakeAnalyticsClient.BuildJob(Account, buildJobParameters)); } else { var jobId = DataLakeAnalyticsClient.JobIdQueue.Count == 0 ? Guid.NewGuid() : DataLakeAnalyticsClient.JobIdQueue.Dequeue(); var createJobParameters = new CreateJobParameters { Type = jobType, Name = Name, DegreeOfParallelism = DegreeOfParallelism, Priority = Priority, Properties = properties, }; if (ParameterSetName.Equals(USqlJobParameterSetNameAndRecurrence) || ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) || ParameterSetName.Equals(USqlJobWithScriptPathAndRecurrence) || ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline)) { createJobParameters.Related = new JobRelationshipProperties { RecurrenceId = RecurrenceId, RecurrenceName = RecurrenceName }; if (ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) || ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline)) { createJobParameters.Related.PipelineId = PipelineId; createJobParameters.Related.PipelineName = PipelineName; createJobParameters.Related.PipelineUri = PipelineUri; createJobParameters.Related.RunId = RunId; } } WriteObject(DataLakeAnalyticsClient.SubmitJob(Account, jobId, createJobParameters)); } }