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));
        }
Example #2
0
        internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var entityKinds = rootElement
                              .GetDescendants <SyntaxElement>(s => s.Kind == SyntaxKind.TableKeyword ||
                                                              s.Kind == SyntaxKind.DatabaseKeyword)
                              .Select(s => s.Kind);

            if (!entityKinds.Any())
            {
                throw new DeltaException("Alter caching policy requires to act on a table or database (cluster isn't supported)");
            }

            var entityKind = entityKinds.First();
            var entityType = entityKind == SyntaxKind.TableKeyword
                ? EntityType.Table
                : EntityType.Database;
            var entityName = rootElement
                             .GetAtLeastOneDescendant <NameReference>("Name reference")
                             .First();

            return(new DeleteCachingPolicyCommand(
                       entityType,
                       EntityName.FromCode(entityName.Name)));
        }