Exemplo n.º 1
0
class CreateByImportDelimForm(forms.Form):
  """Form for step 2 (picking delimiter) of the import wizard"""
  delimiter = ChoiceOrOtherField(required=False, initial=TERMINATOR_CHOICES[0][0],
                                 choices=TERMINATOR_CHOICES)
  file_type = forms.CharField(widget=forms.HiddenInput, required=True)

  def clean(self):
    # ChoiceOrOtherField doesn't work with required=True
    delimiter = self.cleaned_data.get('delimiter')
    if not delimiter:
      raise forms.ValidationError('Delimiter value is required')
    _clean_terminator(delimiter)
    return self.cleaned_data

  def old(self):
    if delimiter.isdigit():
      try:
        chr(int(delimiter))
        return int(delimiter)
      except ValueError:
        raise forms.ValidationError('Delimiter value must be smaller than 256')
    val = delimiter.decode('string_escape')
    if len(val) != 1:
      raise forms.ValidationError('Delimiter must be exactly one character')
    return ord(val)
Exemplo n.º 2
0
class CreateByImportDelimForm(forms.Form):
    """Form for step 2 (picking delimiter) of the import wizard"""
    delimiter = ChoiceOrOtherField(label=_t('Delimiter'),
                                   required=False,
                                   initial=TERMINATOR_CHOICES[0][0],
                                   choices=TERMINATOR_CHOICES)
    file_type = forms.CharField(widget=forms.HiddenInput, required=True)
    read_column_headers = forms.BooleanField(
        required=False,
        initial=False,
        label=_t("Read column headers"),
        help_text=_t("Read first row of the file as column headers."))

    def clean(self):
        # ChoiceOrOtherField doesn't work with required=True
        delimiter = self.cleaned_data.get('delimiter')
        if delimiter.isdigit():
            try:
                chr(int(delimiter))
                return int(delimiter)
            except ValueError:
                raise forms.ValidationError(
                    _('Delimiter value must be smaller than 256.'))
        if not delimiter:
            raise forms.ValidationError(_('Delimiter value is required.'))
        _clean_terminator(delimiter)
        return self.cleaned_data
Exemplo n.º 3
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="")
Exemplo n.º 4
0
Arquivo: forms.py Projeto: zlcken/hue
class CreateTableForm(DependencyAwareForm):
  """
  Form used in the create table page
  """
  dependencies = []

  # Basic Data
  name = common.HiveIdentifierField(label=_t("Table Name"), required=True)
  comment = forms.CharField(label=_t("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(label=_t("Field terminator"), required=False, initial=TERMINATOR_CHOICES[0][0],
    choices=TERMINATOR_CHOICES)
  collection_terminator = ChoiceOrOtherField(label=_t("Collection terminator"), required=False, initial=TERMINATOR_CHOICES[1][0],
    choices=TERMINATOR_CHOICES)
  map_key_terminator = ChoiceOrOtherField(label=_t("Map key terminator"), 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=_t("SerDe Name"))
  serde_properties = forms.CharField(
                        required=False,
                        help_text=_t("Comma-separated list of key-value pairs. E.g. '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=_t("InputFormat Class"))
  output_format_class = forms.CharField(required=False, label=_t("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=_t("Use default location."))
  external_location = forms.CharField(required=False, help_text=_t("Path to HDFS directory or file of table data."))

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

  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.db, self.cleaned_data['name'], self.database)
Exemplo n.º 5
0
 class DjangoForm(forms.Form):
     input = PathListField(
         required=True,
         initial=["$input"],
         help_text="Input paths (may be files or folders).")
     output = CharField(
         required=True,
         initial="$output",
         help_text="Output directory.  Must not already exist.")
     mapper_cmd = CharField(
         required=True,
         initial="<python yourscript.py --map>",
         help_text=
         "Command to execute for map tasks (exclusive with mapper_class).")
     mapper_class = CharField(
         required=False,
         initial="",
         help_text=
         "Class to execute for map tasks (exclusive with mapper_cmd).")
     combiner_class = CharField(
         required=False,
         help_text="(Optional) Class to execute as combiner.")
     reducer_cmd = CharField(
         required=False,
         initial="<python yourscript.py --reduce>",
         help_text=
         "(Optional.)  Command to execute for reduce tasks (exclusive with reducer_class)"
     )
     reducer_class = CharField(
         required=False,
         initial="",
         help_text=
         "Class to execute for reduce tasks (exclusive with reducer_cmd)")
     inputformat_class = ChoiceOrOtherField(
         required=False,
         initial="org.apache.hadoop.mapred.TextInputFormat",
         choices=(
             pair_up("org.apache.hadoop.mapred.TextInputFormat"),
             pair_up(
                 "org.apache.hadoop.mapred.SequenceFileAsTextInputFormat"),
         ),
         help_text="Built-in input format, or class of custom input format."
     )
     outputformat_class = ChoiceOrOtherField(
         required=False,
         initial="org.apache.hadoop.mapred.TextOutputFormat",
         choices=(pair_up("org.apache.hadoop.mapred.TextOutputFormat"), ),
         help_text="Built-in output format, or class of custom input format."
     )
     partitioner_class = CharField(
         required=False, help_text="(Optional) class name of partitioner.")
     num_reduce_tasks = IntegerField(
         required=False,
         initial=1,
         help_text="Number of reduce tasks.  Set to 0 to disable reducers.")
     inputreader = CharField(required=False,
                             help_text="(Optional) Inputreader spec.")
     cache_files = PathListField(
         required=False,
         initial=["<yourscript.py>"],
         label="Required Files",
         help_text="Files (on cluster) to send as part of job.")
     cache_archives = PathListField(
         required=False,
         help_text="Archives (zip, jar) (on cluster) to send as part of job."
     )
     hadoop_properties = KeyValueField(
         required=False,
         help_text='Hadoop options in format property=value.')