mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
3491 Kusto Execute Function support (#1055)
* 3491 Added GenerateExecuteFunctionScript to IDataSource, DataSourceBase, and KustoDataSource. Added ExecutionFunction to Scripter and IScripter. * 3491 Refactored GenerateScriptForFunction in ScriptAsScriptingOperation to handle execute and alter
This commit is contained in:
@@ -105,6 +105,8 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
|
|
||||||
public abstract string GenerateAlterFunctionScript(string functionName);
|
public abstract string GenerateAlterFunctionScript(string functionName);
|
||||||
|
|
||||||
|
public abstract string GenerateExecuteFunctionScript(string functionName);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public DataSourceType DataSourceType { get; protected set; }
|
public DataSourceType DataSourceType { get; protected set; }
|
||||||
|
|
||||||
|
|||||||
@@ -123,10 +123,17 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
bool Exists(DataSourceObjectMetadata objectMetadata);
|
bool Exists(DataSourceObjectMetadata objectMetadata);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets FunctionInfo object for a function
|
/// Generates an alter script for a function
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="functionName"></param>
|
/// <param name="functionName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
string GenerateAlterFunctionScript(string functionName);
|
string GenerateAlterFunctionScript(string functionName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates an execute script for a function
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="functionName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
string GenerateExecuteFunctionScript(string functionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1047,6 +1047,15 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
return alterCommand.ToString();
|
return alterCommand.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string GenerateExecuteFunctionScript(string functionName)
|
||||||
|
{
|
||||||
|
var functionInfo = GetFunctionInfo(functionName);
|
||||||
|
|
||||||
|
return functionInfo == null
|
||||||
|
? string.Empty
|
||||||
|
: $"{functionInfo.Name}{functionInfo.Parameters}";
|
||||||
|
}
|
||||||
|
|
||||||
private string GenerateMetadataKey(string databaseName, string objectName)
|
private string GenerateMetadataKey(string databaseName, string objectName)
|
||||||
{
|
{
|
||||||
return string.IsNullOrWhiteSpace(objectName) ? databaseName : $"{databaseName}.{objectName}";
|
return string.IsNullOrWhiteSpace(objectName) ? databaseName : $"{databaseName}.{objectName}";
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ namespace Microsoft.Kusto.ServiceLayer.Scripting
|
|||||||
{
|
{
|
||||||
string SelectFromTableOrView(IDataSource dataSource, Urn urn);
|
string SelectFromTableOrView(IDataSource dataSource, Urn urn);
|
||||||
string AlterFunction(IDataSource dataSource, ScriptingObject scriptingObject);
|
string AlterFunction(IDataSource dataSource, ScriptingObject scriptingObject);
|
||||||
|
string ExecuteFunction(IDataSource dataSource, ScriptingObject scriptingObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ namespace Microsoft.Kusto.ServiceLayer.Scripting
|
|||||||
// TODO: Not including the header by default. We have to get this option from client
|
// TODO: Not including the header by default. We have to get this option from client
|
||||||
options.IncludeHeaders = false;
|
options.IncludeHeaders = false;
|
||||||
|
|
||||||
// Scripting data is not avaialable in the scripter
|
// Scripting data is not available in the scripter
|
||||||
options.ScriptData = false;
|
options.ScriptData = false;
|
||||||
SetScriptingOptions(options);
|
SetScriptingOptions(options);
|
||||||
|
|
||||||
@@ -82,7 +82,8 @@ namespace Microsoft.Kusto.ServiceLayer.Scripting
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ScriptingOperationType.Alter:
|
case ScriptingOperationType.Alter:
|
||||||
resultScript = GenerateScriptAlter(DataSource, urns);
|
case ScriptingOperationType.Execute:
|
||||||
|
resultScript = GenerateScriptForFunction(DataSource);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,16 +154,25 @@ namespace Microsoft.Kusto.ServiceLayer.Scripting
|
|||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateScriptAlter(IDataSource dataSource, UrnCollection urns)
|
private string GenerateScriptForFunction(IDataSource dataSource)
|
||||||
{
|
{
|
||||||
ScriptingObject scriptingObject = this.Parameters.ScriptingObjects[0];
|
ScriptingObject scriptingObject = this.Parameters.ScriptingObjects[0];
|
||||||
Urn objectUrn = urns[0];
|
|
||||||
|
|
||||||
if (string.Equals(scriptingObject.Type, "Function", StringComparison.CurrentCultureIgnoreCase))
|
if (!string.Equals(scriptingObject.Type, "Function", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Parameters.Operation == ScriptingOperationType.Alter)
|
||||||
{
|
{
|
||||||
return _scripter.AlterFunction(dataSource, scriptingObject);
|
return _scripter.AlterFunction(dataSource, scriptingObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Parameters.Operation == ScriptingOperationType.Execute)
|
||||||
|
{
|
||||||
|
return _scripter.ExecuteFunction(dataSource, scriptingObject);
|
||||||
|
}
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,5 +32,11 @@ namespace Microsoft.Kusto.ServiceLayer.Scripting
|
|||||||
var functionName = scriptingObject.Name.Substring(0, scriptingObject.Name.IndexOf('('));
|
var functionName = scriptingObject.Name.Substring(0, scriptingObject.Name.IndexOf('('));
|
||||||
return dataSource.GenerateAlterFunctionScript(functionName);
|
return dataSource.GenerateAlterFunctionScript(functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ExecuteFunction(IDataSource dataSource, ScriptingObject scriptingObject)
|
||||||
|
{
|
||||||
|
var functionName = scriptingObject.Name.Substring(0, scriptingObject.Name.IndexOf('('));
|
||||||
|
return dataSource.GenerateExecuteFunctionScript(functionName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user