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)); }
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)); }
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)); }
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)); }