예제 #1
0
class ColumnTypeForm(DependencyAwareForm):
    """
    Form used to specify a column during table creation
    """
    dependencies = [
        ("column_type", "array", "array_type"),
        ("column_type", "map", "map_key_type"),
        ("column_type", "map", "map_value_type"),
    ]
    column_name = common.HiveIdentifierField(required=True)
    column_type = forms.ChoiceField(required=True,
                                    choices=common.to_choices(sorted(HIVE_TYPES)),
                                    initial=HIVE_TYPES[0])
    array_type = forms.ChoiceField(required=False,
                                   choices=common.to_choices(sorted(HIVE_PRIMITIVE_TYPES)),
                                   initial=HIVE_PRIMITIVE_TYPES[0],
                                   label="Array Value Type")
    map_key_type = forms.ChoiceField(required=False,
                                     choices=common.to_choices(sorted(HIVE_PRIMITIVE_TYPES)),
                                     initial=HIVE_PRIMITIVE_TYPES[0],
                                     help_text="Specify if column_type is map.")
    map_value_type = forms.ChoiceField(required=False,
                                       choices=common.to_choices(sorted(HIVE_PRIMITIVE_TYPES)),
                                       initial=HIVE_PRIMITIVE_TYPES[0],
                                       help_text="Specify if column_type is map.")
예제 #2
0
class CreateTableFromFileForm(forms.Form):
    """
    Form used in the create table from file page
    """

    # Basic Data
    name = common.HiveIdentifierField(label="Table Name", required=False)
    comment = forms.CharField(label="Description", required=False)

    path = filebrowser.forms.PathField(label="Input File")

    # csv/tsv files
    encoding = UnicodeEncodingField()
    delimiter = ChoiceOrOtherField(required=False, initial=TERMINATOR_CHOICES[0][0], choices=TERMINATOR_CHOICES)
    replace_delimiter_with = ChoiceOrOtherField(required=False, initial=TERMINATOR_CHOICES[0][0], choices=TERMINATOR_CHOICES,
                                          label="Replace delimiter with")
    read_column_headers = forms.BooleanField(required=False, initial=True,
                                             label="Read column headers",
                                             help_text="")
    import_data = forms.BooleanField(required=False, initial=True,
                                     label="Import data",
                                     help_text="")
    autodetect_delimiter = forms.BooleanField(required=False, initial=True,
                                            label="Autodetect delimiter",
                                            help_text="")
    ignore_whitespaces = forms.BooleanField(required=False, initial=False,
                                            label="Ignore whitespaces",
                                            help_text="")
    ignore_tabs = forms.BooleanField(required=False, initial=False,
                                     label="Ignore tabs",
                                     help_text="")
    single_line_comment = forms.CharField(label="Single line comment", required=False)
    java_style_comments = forms.BooleanField(required=False, initial=False,
                                             label="Java-style comments",
                                             help_text="")

    apply_excel_dialect = forms.BooleanField(required=False, initial=True,
                                             label="Read column headers",
                                             help_text="")

    # xls/xlsx files
    xls_sheet = ChoiceFieldExtended(label="Sheet", required=False)
    xls_cell_range = forms.CharField(label="Cell range", required=False)
    xls_read_column_headers = forms.BooleanField(required=False, initial=True,
                                             label="Read column headers",
                                             help_text="")
예제 #3
0
class CreateDatabaseForm(DependencyAwareForm):
    """
    Form used in the create database page
    """
    dependencies = []

    # Basic Data
    db_name = common.HiveIdentifierField(label="Database Name", required=True)
    comment = forms.CharField(label="Description", required=False)

    # External if not true
    use_default_location = forms.BooleanField(required=False, initial=True, label="Use default location")
    external_location = forms.CharField(required=False, help_text="Path to HDFS directory or file of database data.")

    dependencies += [("use_default_location", False, "external_location")]

    def __init__(self, *args, **kwargs):
        DependencyAwareForm.__init__(self, *args, **kwargs)
        self.database_list = []

    def clean_db_name(self):
        return _clean_databasename(self.database_list, self.cleaned_data['db_name'])
예제 #4
0
class PartitionTypeForm(forms.Form):
    column_name = common.HiveIdentifierField(required=True)
    column_type = forms.ChoiceField(required=True, choices=common.to_choices(sorted(HIVE_PRIMITIVE_TYPES)),
                                    initial=HIVE_PRIMITIVE_TYPES[0])
예제 #5
0
class CreateTableForm(DependencyAwareForm):
    """
    Form used in the create table page
    """
    dependencies = []

    # Basic Data
    name = common.HiveIdentifierField(label="Table Name", required=True)
    comment = forms.CharField(label="Description", required=False)

    # Row Formatting
    row_format = forms.ChoiceField(required=True,
                                   choices=common.to_choices(["Delimited", "SerDe"]),
                                   initial="Delimited")

    # Delimited Row
    # These initials are per LazySimpleSerDe.DefaultSeparators
    field_terminator = ChoiceOrOtherField(required=False, initial=TERMINATOR_CHOICES[0][0],
                                          choices=TERMINATOR_CHOICES)
    collection_terminator = ChoiceOrOtherField(required=False, initial=TERMINATOR_CHOICES[1][0],
                                               choices=TERMINATOR_CHOICES)
    map_key_terminator = ChoiceOrOtherField(required=False, initial=TERMINATOR_CHOICES[2][0],
                                            choices=TERMINATOR_CHOICES)
    dependencies += [
        ("row_format", "Delimited", "field_terminator"),
        ("row_format", "Delimited", "collection_terminator"),
        ("row_format", "Delimited", "map_key_terminator"),
    ]

    # Serde Row
    serde_name = forms.CharField(required=False, label="SerDe Name")
    serde_properties = forms.CharField(
        required=False,
        help_text="Comma-separated list of key-value pairs, eg., 'p1=v1, p2=v2'")

    dependencies += [
        ("row_format", "SerDe", "serde_name"),
        ("row_format", "SerDe", "serde_properties"),
    ]

    # File Format
    file_format = forms.ChoiceField(required=False, initial="TextFile",
                                    choices=common.to_choices(["TextFile", "SequenceFile", "InputFormat"]),
                                    widget=forms.RadioSelect)
    input_format_class = forms.CharField(required=False, label="InputFormat Class")
    output_format_class = forms.CharField(required=False, label="OutputFormat Class")

    dependencies += [
        ("file_format", "InputFormat", "input_format_class"),
        ("file_format", "InputFormat", "output_format_class"),
    ]

    # External?
    use_default_location = forms.BooleanField(required=False, initial=True,
                                              label="Use default location")
    external_location = forms.CharField(required=False, help_text="Path to HDFS directory or file of table data.")

    dependencies += [
        ("use_default_location", False, "external_location")
    ]

    def __init__(self, *args, **kwargs):
        DependencyAwareForm.__init__(self, *args, **kwargs)
        self.table_list = []

    def clean_field_terminator(self):
        return _clean_terminator(self.cleaned_data.get('field_terminator'))

    def clean_collection_terminator(self):
        return _clean_terminator(self.cleaned_data.get('collection_terminator'))

    def clean_map_key_terminator(self):
        return _clean_terminator(self.cleaned_data.get('map_key_terminator'))

    def clean_name(self):
        return _clean_tablename(self.table_list, self.cleaned_data['name'])