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
                             .GetDescendants <NameReference>(n => n.NameInParent == "TableName" ||
                                                             n.NameInParent == "DatabaseName" ||
                                                             n.NameInParent == "Selector")
                             .Last();

            var(hotData, hotIndex) = ExtractHotDurations(rootElement);

            return(new AlterCachingPolicyCommand(
                       entityType,
                       EntityName.FromCode(entityName.Name),
                       hotData,
                       hotIndex));
        }
        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 retention 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.GetDescendants <NameReference>().Last();
            var policyText = QuotedText.FromLiteral(
                rootElement.GetUniqueDescendant <LiteralExpression>(
                    "RetentionPolicy",
                    e => e.NameInParent == "RetentionPolicy"));
            var policy = Deserialize <JsonDocument>(policyText.Text);

            if (policy == null)
            {
                throw new DeltaException(
                          $"Can't extract policy objects from {policyText.ToScript()}");
            }

            return(new AlterRetentionPolicyCommand(
                       entityType,
                       EntityName.FromCode(entityName.Name),
                       policy));
        }
Exemplo n.º 3
0
        internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var cleanTableName = rootElement
                                 .GetDescendants <TokenName>(e => e.NameInParent == "Name")
                                 .FirstOrDefault();
            var tableName = rootElement.GetDescendants <NameReference>().Last();

            if ((cleanTableName == null || cleanTableName.Name.Text == string.Empty) &&
                tableName == null)
            {
                throw new DeltaException("Can't find table name");
            }

            var policiesText = QuotedText.FromLiteral(
                rootElement.GetUniqueDescendant <LiteralExpression>(
                    "UpdatePolicy",
                    e => e.NameInParent == "UpdatePolicy"));
            var policies = Deserialize <UpdatePolicy[]>(policiesText.Text);

            if (policies == null)
            {
                throw new DeltaException(
                          $"Can't extract policy objects from {policiesText.ToScript()}");
            }

            return(new AlterUpdatePolicyCommand(
                       EntityName.FromCode(tableName.Name),
                       policies));
        }
Exemplo n.º 4
0
        internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var tableName  = rootElement.GetDescendants <NameReference>().Last();
            var policyText = QuotedText.FromLiteral(
                rootElement.GetUniqueDescendant <LiteralExpression>(
                    "AutoDeletePolicy",
                    e => e.NameInParent == "AutoDeletePolicy"));
            var policy = Deserialize <JsonDocument>(policyText.Text);

            if (policy == null)
            {
                throw new DeltaException(
                          $"Can't extract policy objects from {policyText.ToScript()}");
            }

            return(new AlterAutoDeletePolicyCommand(EntityName.FromCode(tableName.Name), policy));
        }
Exemplo n.º 5
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("Delete ingestionbatching 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.GetFirstDescendant <NameReference>();

            return(new DeleteIngestionBatchingPolicyCommand(entityType, EntityName.FromCode(entityName.Name)));
        }
        internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var tableNames = rootElement
                             .GetDescendants <SyntaxElement>(n => n.NameInParent == "Name"
                             //  Different type depending if it's a simple name or not
                                                             && (n is TokenName || n is LiteralExpression))
                             //.GetDescendants<LiteralExpression>(n => n.NameInParent == "Name")
                             //.GetDescendants<TokenName>(n => n.NameInParent == "Name")
                             .Select(t => EntityName.FromCode(t));
            var policyText = QuotedText.FromLiteral(
                rootElement.GetUniqueDescendant <LiteralExpression>(
                    "RetentionPolicy",
                    e => e.NameInParent == "RetentionPolicy"));
            var policy = Deserialize <JsonDocument>(policyText.Text);

            if (policy == null)
            {
                throw new DeltaException(
                          $"Can't extract policy objects from {policyText.ToScript()}");
            }

            return(new AlterTablesRetentionPolicyCommand(tableNames, policy));
        }
Exemplo n.º 7
0
        internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var entityName = rootElement.GetFirstDescendant <NameReference>();

            return(new DeleteAutoDeletePolicyCommand(EntityName.FromCode(entityName.Name)));
        }