public InnerTable( EntityName tableName, IEnumerable <TableColumn> columns) { TableName = tableName; Columns = columns.ToImmutableArray(); }
internal static CommandBase FromCode(SyntaxElement rootElement) { var tableNameDeclaration = rootElement.GetUniqueDescendant <NameDeclaration>( "Table Name", n => n.NameInParent == "TableName"); var mappingNameExpression = rootElement.GetUniqueDescendant <LiteralExpression>( "Mapping Name", n => n.NameInParent == "MappingName"); var mappingKindToken = rootElement.GetUniqueDescendant <SyntaxToken>( "Mapping Kind", n => n.NameInParent == "MappingKind"); var mappingFormatExpression = rootElement.GetUniqueDescendant <LiteralExpression>( "Mapping Format", n => n.NameInParent == "MappingFormat"); var mappingFormatFirstPart = QuotedText.FromLiteral(mappingFormatExpression); var mappingFormatExtraParts = rootElement .GetDescendants <CompoundStringLiteralExpression>() .SelectMany(c => c.Tokens) .Select(t => QuotedText.FromToken(t)); var mappingFormatParts = mappingFormatExtraParts .Prepend(mappingFormatFirstPart) .Select(q => q.Text); var mappingFormat = string.Concat(mappingFormatParts); var command = new CreateMappingCommand( EntityName.FromCode(tableNameDeclaration), mappingKindToken.Text, QuotedText.FromLiteral(mappingNameExpression), QuotedText.FromText(mappingFormat) !); return(command); }
private void ValidateNoTableParameterAfterScalar( EntityName functionName, IImmutableList <TypedParameterModel> parameters) { // This implements the rule cited in a note in // https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/functions/user-defined-functions#input-arguments // "When using both tabular input arguments and scalar input arguments, // put all tabular input arguments before the scalar input arguments." if (parameters.Count() > 2) { var skipEnd = parameters.Take(parameters.Count - 1); var skipBeginning = parameters.Skip(1); var zipped = skipEnd.Zip(skipBeginning, (p1, p2) => (current: p1, next: p2)); var violation = zipped .Where(p => p.current.ComplexType == null && p.next.ComplexType != null); var firstViolation = violation.FirstOrDefault(); if (violation.Any()) { throw new DeltaException( $"In function parameters, table types should preceed scalar parameters. " + $"This rule isn't respected in function '{functionName}': " + $"parameter '{firstViolation.next.ParameterName}' is a table parameter " + $"and follows '{firstViolation.current.ParameterName}' which is a scalar"); } } }
internal static CommandBase FromCode(SyntaxElement rootElement) { var tableName = rootElement.GetUniqueDescendant <NameDeclaration>( "TableName", n => n.NameInParent == "TableName"); var folder = GetProperty(rootElement, SyntaxKind.FolderKeyword); var docString = GetProperty(rootElement, SyntaxKind.DocStringKeyword); var columns = rootElement .GetDescendants <NameDeclaration>(n => n.NameInParent == "ColumnName") .Select(n => n.Parent) .Select(n => new { Name = n.GetUniqueDescendant <NameDeclaration>("Table column name"), Type = n.GetUniqueDescendant <PrimitiveTypeExpression>("Table column type") }) .Select(c => new TableColumn( EntityName.FromCode(c.Name), c.Type.Type.Text)); return(new CreateTableCommand( EntityName.FromCode(tableName), columns, folder, docString)); }
internal DropTableColumnsCommand( EntityName tableName, IImmutableList <EntityName> columnNames) { TableName = tableName; ColumnNames = columnNames; }
internal AlterMergeTableColumnDocStringsCommand( EntityName tableName, IEnumerable<ColumnDocString> columns) { TableName = tableName; Columns = columns.ToImmutableArray(); }
internal static CommandBase FromCode(SyntaxElement rootElement) { var functionName = EntityName.FromCode( rootElement.GetUniqueDescendant <SyntaxElement>( "Function Name", e => e.NameInParent == "FunctionName")); var functionDeclaration = rootElement .GetAtLeastOneDescendant <FunctionDeclaration>("Function declaration") .First(); var body = TrimFunctionSchemaBody(functionDeclaration.Body.ToString()); var parameters = functionDeclaration .Parameters .Parameters .Select(p => p.Element) .Select(fp => GetParameter(fp)); var folder = GetProperty(rootElement, SyntaxKind.FolderKeyword); var docString = GetProperty(rootElement, SyntaxKind.DocStringKeyword); return(new CreateFunctionCommand( functionName, parameters, body, folder, docString)); }
internal static CommandBase FromCode(SyntaxElement rootElement) { var identifiers = rootElement .GetDescendants<SyntaxNode>(e => e.NameInParent == "Name" && e.Kind != SyntaxKind.BracketedName) .Select(t => EntityName.FromCode(t)); var literals = rootElement .GetDescendants<LiteralExpression>(e => e.NameInParent == "DocString") .Select(l => new QuotedText(l.LiteralValue.ToString()!)); if (identifiers.Count() < 1) { throw new DeltaException("There should be at least one identifier in the command"); } if (identifiers.Count() != literals.Count() + 1) { throw new DeltaException("Mismatch number of identifiers vs literals"); } var tableName = identifiers.First(); var columns = identifiers .Skip(1) .Zip(literals, (id, lit) => new ColumnDocString(id, lit)); return new AlterMergeTableColumnDocStringsCommand(tableName, columns); }
public DropMappingCommand( EntityName tableName, string mappingKind, QuotedText mappingName) { TableName = tableName; MappingKind = mappingKind.ToLower(); MappingName = mappingName; }
public TableColumn(EntityName columnName, string primitiveType) { if (string.IsNullOrWhiteSpace(primitiveType)) { throw new ArgumentNullException(nameof(primitiveType)); } ColumnName = columnName; PrimitiveType = primitiveType; }
internal AlterColumnTypeCommand( EntityName tableName, EntityName columnName, string type) { TableName = tableName; ColumnName = columnName; Type = type; }
public CreateMappingCommand( EntityName tableName, string mappingKind, QuotedText mappingName, QuotedText mappingAsJson) { TableName = tableName; MappingKind = mappingKind.ToLower(); MappingName = mappingName; MappingAsJson = mappingAsJson; }
internal CreateTableCommand( EntityName tableName, IEnumerable <TableColumn> columns, QuotedText?folder, QuotedText?docString) { TableName = tableName; Columns = columns.ToImmutableArray(); Folder = folder; DocString = docString; }
public TypedParameterModel( EntityName parameterName, string primitiveType, string?defaultValue) : this(parameterName) { if (string.IsNullOrWhiteSpace(primitiveType)) { throw new ArgumentNullException(nameof(primitiveType)); } PrimitiveType = primitiveType; DefaultValue = defaultValue; }
internal static CommandBase FromCode(SyntaxElement rootElement) { var tableNameReference = rootElement.GetUniqueDescendant <NameReference>( "Table name", n => n.NameInParent == "TableName"); var columnNameReferences = rootElement.GetDescendants <NameReference>( n => n.NameInParent != "TableName"); var tableName = new EntityName(tableNameReference.Name.SimpleName); var columnNames = columnNameReferences .Select(n => new EntityName(n.Name.SimpleName)) .ToImmutableArray(); return(new DropTableColumnsCommand(tableName, columnNames)); }
internal static CommandBase FromCode(SyntaxElement rootElement) { var nameReferences = rootElement.GetDescendants <NameReference>(); if (nameReferences.Count != 2) { throw new DeltaException($"Expected 2 names but got {nameReferences.Count}"); } var tableName = new EntityName(nameReferences[0].Name.SimpleName); var columnName = new EntityName(nameReferences[1].Name.SimpleName); var typeExpression = rootElement.GetUniqueDescendant <PrimitiveTypeExpression>("Primitive type"); var type = typeExpression.Type.ValueText; return(new AlterColumnTypeCommand(tableName, columnName, type)); }
private static TypedParameterModel GetParameter(FunctionParameter functionParameter) { var declaration = functionParameter.NameAndType; var defaultValue = functionParameter.DefaultValue; var(name, type) = declaration .GetImmediateDescendants <SyntaxNode>() .ExtractChildren <NameDeclaration, TypeExpression>("Parameter pair"); if (type is PrimitiveTypeExpression) { var typeExpression = type as PrimitiveTypeExpression; return(new TypedParameterModel( EntityName.FromCode(name), typeExpression !.Type.ValueText, defaultValue != null ? defaultValue.ToString() : null)); } else { var typeExpression = type as SchemaTypeExpression; var cols = typeExpression !.Columns; // Consider the case T(*) if (cols.Count == 1 && cols.First().GetImmediateDescendants <NameAndTypeDeclaration>().Count == 0) { return(new TypedParameterModel( EntityName.FromCode(name), new TableParameterModel(new TableColumn[0]))); } else { var columns = typeExpression ! .Columns .Select(c => c.GetUniqueImmediateDescendant <NameAndTypeDeclaration>("Function parameter table column")) .Select(n => GetColumnSchema(n)); var table = new TableParameterModel(columns); return(new TypedParameterModel( EntityName.FromCode(name), table)); } } }
internal static CommandBase FromCode(SyntaxElement rootElement) { var(folder, docString) = ExtractWithProperties(rootElement); Func <NameDeclaration, InnerTable> tableExtraction = (table) => { var columns = table .Parent .GetDescendants <SeparatedElement>() .Select(s => new TableColumn( EntityName.FromCode(s.GetUniqueDescendant <NameDeclaration>("Column Name")), s.GetUniqueDescendant <PrimitiveTypeExpression>("Column Type").Type.Text)); return(new InnerTable(EntityName.FromCode(table), columns)); }; var tables = rootElement .GetDescendants <NameDeclaration>(n => n.NameInParent == "TableName") .Select(t => tableExtraction(t)); return(new CreateTablesCommand(tables, folder, docString)); }
public CreateFunctionCommand( EntityName functionName, IEnumerable <TypedParameterModel> parameters, string functionBody, QuotedText folder, QuotedText docString) { FunctionName = functionName; Parameters = parameters.ToImmutableArray(); if (functionBody.Trim().StartsWith('{')) { throw new ArgumentException( $"Body should start with curly braces: '{functionBody}'", nameof(functionBody)); } ValidateNoTableParameterAfterScalar(functionName, Parameters); Body = functionBody.Trim().Replace("\r", string.Empty); Folder = folder; DocString = docString; }
internal DropTableCommand(EntityName tableName) { TableName = tableName; }
public ColumnDocString(EntityName columnName, QuotedText docString) { ColumnName = columnName; DocString = docString; }
public TypedParameterModel(EntityName parameterName, TableParameterModel tableSchema) : this(parameterName) { ComplexType = tableSchema; }
private TypedParameterModel(EntityName parameterName) { ParameterName = parameterName; }
internal DropFunctionCommand(EntityName functionName) { FunctionName = functionName; }