def validate_datatype(type, value, entry_schema=None, custom_def=None):
        '''Validate value with given type.

        If type is list or map, validate its entry by entry_schema(if defined)
        If type is a user-defined complex datatype, custom_def is required.
        '''
        if type == Schema.STRING:
            return Constraint.validate_string(value)
        elif type == Schema.INTEGER:
            return Constraint.validate_integer(value)
        elif type == Schema.FLOAT:
            return Constraint.validate_float(value)
        elif type == Schema.NUMBER:
            return Constraint.validate_number(value)
        elif type == Schema.BOOLEAN:
            return Constraint.validate_boolean(value)
        elif type == Schema.TIMESTAMP:
            return Constraint.validate_timestamp(value)
        elif type == Schema.LIST:
            Constraint.validate_list(value)
            if entry_schema:
                DataEntity.validate_entry(value, entry_schema, custom_def)
            return value
        elif type == Schema.SCALAR_UNIT_SIZE:
            return Constraint.validate_scalar_unit_size(value)
        elif type == Schema.MAP:
            Constraint.validate_map(value)
            if entry_schema:
                DataEntity.validate_entry(value, entry_schema, custom_def)
            return value
        else:
            data = DataEntity(type, value, custom_def)
            return data.validate()
Exemple #2
0
    def validate_datatype(type, value, entry_schema=None, custom_def=None):
        '''Validate value with given type.

        If type is list or map, validate its entry by entry_schema(if defined)
        If type is a user-defined complex datatype, custom_def is required.
        '''
        if type == Schema.STRING:
            return Constraint.validate_string(value)
        elif type == Schema.INTEGER:
            return Constraint.validate_integer(value)
        elif type == Schema.FLOAT:
            return Constraint.validate_float(value)
        elif type == Schema.NUMBER:
            return Constraint.validate_number(value)
        elif type == Schema.BOOLEAN:
            return Constraint.validate_boolean(value)
        elif type == Schema.TIMESTAMP:
            return Constraint.validate_timestamp(value)
        elif type == Schema.LIST:
            Constraint.validate_list(value)
            if entry_schema:
                DataEntity.validate_entry(value, entry_schema, custom_def)
            return value
        elif type == Schema.SCALAR_UNIT_SIZE:
            return Constraint.validate_scalar_unit_size(value)
        elif type == Schema.MAP:
            Constraint.validate_map(value)
            if entry_schema:
                DataEntity.validate_entry(value, entry_schema, custom_def)
            return value
        else:
            data = DataEntity(type, value, custom_def)
            return data.validate()
Exemple #3
0
 def _validate_datatype(self):
     dtype = self.schema['type']
     if dtype == self.STRING:
         return Constraint.validate_string(self.value)
     elif dtype == self.INTEGER:
         return Constraint.validate_integer(self.value)
     elif dtype == self.NUMBER:
         return Constraint.validate_number(self.value)
     elif dtype == self.LIST:
         return Constraint.validate_list(self.value)
Exemple #4
0
 def _validate_datatype(self):
     dtype = self.schema['type']
     if dtype == self.STRING:
         return Constraint.validate_string(self.value)
     elif dtype == self.INTEGER:
         return Constraint.validate_integer(self.value)
     elif dtype == self.NUMBER:
         return Constraint.validate_number(self.value)
     elif dtype == self.LIST:
         return Constraint.validate_list(self.value)