internal static CommandBase FromCode(SyntaxElement rootElement) { var tableNameReference = rootElement.GetUniqueDescendant <NameReference>( "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 command = new DropMappingCommand( new EntityName(tableNameReference.SimpleName), mappingKindToken.Text, QuotedText.FromLiteral(mappingNameExpression)); return(command); }
private static CommandBase?CreateCommand( string script, KustoCode code, bool ignoreUnknownCommands) { var commandBlock = code.Syntax as CommandBlock; if (commandBlock == null) { throw new DeltaException("Script isn't a command"); } var unknownCommand = commandBlock.GetDescendants <UnknownCommand>().FirstOrDefault(); if (unknownCommand != null) { return(RerouteUnknownCommand(script, unknownCommand, ignoreUnknownCommands)); } else { var customCommand = commandBlock.GetUniqueDescendant <CustomCommand>("custom command"); switch (customCommand.CommandKind) { case "CreateFunction": case "CreateOrAlterFunction": return(CreateFunctionCommand.FromCode(commandBlock)); case "DropFunction": return(DropFunctionCommand.FromCode(commandBlock)); case "DropFunctions": return(DropFunctionsCommand.FromCode(commandBlock)); case "CreateTable": return(CreateTableCommand.FromCode(commandBlock)); case "CreateMergeTable": // We need to do this since the parsing is quite different with the with-node // between a .create and .create-merge (for unknown reasons) return(ParseAndCreateCommand( ReplaceFirstOccurence(script, "create-merge", "create"), ignoreUnknownCommands)); case "AlterMergeTable": return(ParseAndCreateCommand( ReplaceFirstOccurence(script, "alter-merge", "create"), ignoreUnknownCommands)); case "CreateTables": return(CreateTablesCommand.FromCode(commandBlock)); case "DropTable": return(DropTableCommand.FromCode(commandBlock)); case "DropTables": return(DropTablesCommand.FromCode(commandBlock)); case "AlterColumnType": return(AlterColumnTypeCommand.FromCode(commandBlock)); case "AlterMergeTableColumnDocStrings": return(AlterMergeTableColumnDocStringsCommand.FromCode(commandBlock)); case "DropTableColumns": return(DropTableColumnsCommand.FromCode(commandBlock)); case "CreateTableIngestionMapping": return(CreateMappingCommand.FromCode(commandBlock)); case "DropTableIngestionMapping": return(DropMappingCommand.FromCode(commandBlock)); case "AlterTablePolicyUpdate": return(AlterUpdatePolicyCommand.FromCode(commandBlock)); #region Policies case "AlterTablePolicyAutoDelete": return(AlterAutoDeletePolicyCommand.FromCode(commandBlock)); case "DeleteTablePolicyAutoDelete": return(DeleteAutoDeletePolicyCommand.FromCode(commandBlock)); case "AlterDatabasePolicyCaching": case "AlterTablePolicyCaching": var partitioning = commandBlock.GetDescendants <SyntaxElement>(s => s.Kind == SyntaxKind.PartitioningKeyword).Count(); if (partitioning == 1) { if (ignoreUnknownCommands) { return(null); } else { throw new DeltaException( $"Can't handle CommandKind 'AlterTablePolicyPartitioning'"); } } else { return(AlterCachingPolicyCommand.FromCode(commandBlock)); } case "DeleteDatabasePolicyCaching": case "DeleteTablePolicyCaching": return(DeleteCachingPolicyCommand.FromCode(commandBlock)); case "AlterDatabasePolicyIngestionBatching": case "AlterTablePolicyIngestionBatching": return(AlterIngestionBatchingPolicyCommand.FromCode(commandBlock)); case "DeleteDatabasePolicyIngestionBatching": case "DeleteTablePolicyIngestionBatching": return(DeleteIngestionBatchingPolicyCommand.FromCode(commandBlock)); case "AlterDatabasePolicyMerge": case "AlterTablePolicyMerge": return(AlterMergePolicyCommand.FromCode(commandBlock)); case "DeleteDatabasePolicyMerge": case "DeleteTablePolicyMerge": return(DeleteMergePolicyCommand.FromCode(commandBlock)); case "AlterDatabasePolicyRetention": case "AlterTablePolicyRetention": return(AlterRetentionPolicyCommand.FromCode(commandBlock)); case "AlterTablesPolicyRetention": return(AlterTablesRetentionPolicyCommand.FromCode(commandBlock)); case "DeleteDatabasePolicyRetention": case "DeleteTablePolicyRetention": return(DeleteRetentionPolicyCommand.FromCode(commandBlock)); case "AlterDatabasePolicySharding": case "AlterTablePolicySharding": return(AlterShardingPolicyCommand.FromCode(commandBlock)); case "DeleteDatabasePolicySharding": case "DeleteTablePolicySharding": return(DeleteShardingPolicyCommand.FromCode(commandBlock)); #endregion default: if (ignoreUnknownCommands) { return(null); } else { throw new DeltaException( $"Can't handle CommandKind '{customCommand.CommandKind}'"); } } } }