Exemplo n.º 1
0
    /// <summary>
    /// Add a new column to the table. The column defaults to a
    /// nullable non-key column.
    /// </summary>
    /// <param name="name">The column name.</param>
    /// <param name="type">The column type.</param>
    /// <param name="configure">A delegate to further configure the column.</param>
    public AlterTableBuilder AddColumn(
        string name, KuduType type, Action <ColumnBuilder>?configure = null)
    {
        var columnBuilder = new ColumnBuilder(name, type);

        configure?.Invoke(columnBuilder);

        var schema = columnBuilder.Build();

        if (!schema.IsNullable && schema.DefaultValue is null)
        {
            ThrowNewColumnMustHaveDefaultException();
        }

        if (schema.IsKey)
        {
            ThrowAddKeyColumnException();
        }

        _request.AlterSchemaSteps.Add(new Step
        {
            Type      = StepType.AddColumn,
            AddColumn = new AddColumn
            {
                Schema = schema.ToColumnSchemaPb()
            }
        });

        return(this);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Add a new column to the table. The column defaults to a
    /// nullable non-key column.
    /// </summary>
    /// <param name="name">The column name.</param>
    /// <param name="type">The column type.</param>
    /// <param name="configure">A delegate to further configure the column.</param>
    public TableBuilder AddColumn(
        string name, KuduType type, Action <ColumnBuilder>?configure = null)
    {
        var builder = new ColumnBuilder(name, type);

        configure?.Invoke(builder);
        var columnSchemaPb = builder.Build().ToColumnSchemaPb();

        _createTableRequest.Schema.Columns.Add(columnSchemaPb);
        return(this);
    }