spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdblue <...@git.apache.org>
Subject [GitHub] spark pull request #21306: [SPARK-24252][SQL] Add DataSourceV2 mix-in for ca...
Date Wed, 04 Jul 2018 16:32:50 GMT
Github user rdblue commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21306#discussion_r200171696
  
    --- Diff: sql/core/src/main/java/org/apache/spark/sql/sources/v2/catalog/TableChange.java
---
    @@ -0,0 +1,173 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.sources.v2.catalog;
    +
    +import org.apache.spark.sql.types.DataType;
    +
    +/**
    + * TableChange subclasses represent requested changes to a table. These are passed to
    + * {@link DataSourceCatalog#alterTable}.
    + */
    +public interface TableChange {
    +
    +  /**
    +   * Create a TableChange for adding a top-level column to a table.
    +   * <p>
    +   * Because "." may be interpreted as a field path separator or may be used in field
names, it is
    +   * not allowed in names passed to this method. To add to nested types or to add fields
with
    +   * names that contain ".", use {@link #addColumn(String, String, DataType)}.
    +   *
    +   * @param name the new top-level column name
    +   * @param dataType the new column's data type
    +   * @return a TableChange for the addition
    +   */
    +  static TableChange addColumn(String name, DataType dataType) {
    +    return new AddColumn(null, name, dataType);
    +  }
    +
    +  /**
    +   * Create a TableChange for adding a nested column to a table.
    +   * <p>
    +   * The parent name is used to find the parent struct type where the nested field will
be added.
    +   * If the parent name is null, the new column will be added to the root as a top-level
column.
    +   * If parent identifies a struct, a new column is added to that struct. If it identifies
a list,
    +   * the column is added to the list element struct, and if it identifies a map, the
new column is
    +   * added to the map's value struct.
    +   * <p>
    +   * The given name is used to name the new column and names containing "." are not handled
    +   * differently.
    +   *
    +   * @param parent the new field's parent
    +   * @param name the new field name
    +   * @param dataType the new field's data type
    +   * @return a TableChange for the addition
    +   */
    +  static TableChange addColumn(String parent, String name, DataType dataType) {
    +    return new AddColumn(parent, name, dataType);
    +  }
    +
    +  /**
    +   * Create a TableChange for renaming a field.
    +   * <p>
    +   * The name is used to find the field to rename. The new name will replace the name
of the type.
    +   * For example, renameColumn("a.b.c", "x") should produce column a.b.x.
    +   *
    +   * @param name the current field name
    +   * @param newName the new name
    +   * @return a TableChange for the rename
    +   */
    +  static TableChange renameColumn(String name, String newName) {
    +    return new RenameColumn(name, newName);
    +  }
    +
    +  /**
    +   * Create a TableChange for updating the type of a field.
    +   * <p>
    +   * The name is used to find the field to update.
    +   *
    +   * @param name the field name
    +   * @param newDataType the new data type
    +   * @return a TableChange for the update
    +   */
    +  static TableChange updateColumn(String name, DataType newDataType) {
    +    return new UpdateColumn(name, newDataType);
    +  }
    +
    +  /**
    +   * Create a TableChange for deleting a field from a table.
    +   *
    +   * @param name the name of the field to delete
    +   * @return a TableChange for the delete
    +   */
    +  static TableChange deleteColumn(String name) {
    +    return new DeleteColumn(name);
    +  }
    +
    +  final class AddColumn implements TableChange {
    --- End diff --
    
    Just noticed that these aren't public, but should be because they will be passed to implementations
through `alterTable`.
    
    These should also implement `unapply` for Scala implementations.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message