class PrimaryKeysAddedClusteringKey(Model): __table_name__ = "primary_keys_only" __options__ = {'compaction': {'class': 'LeveledCompactionStrategy'}} new_first_key = columns.Float(primary_key=True) second_key = columns.Integer(primary_key=True)
class PrimaryKeysModelTypeChanged(Model): __table_name__ = "primary_keys_only" __options__ = {'compaction': {'class': 'LeveledCompactionStrategy'}} first_key = columns.Float(primary_key=True) second_key = columns.Integer(primary_key=True)
class ComplexModelRouting(Model): __table_name__ = 'complex_model_routing' partition = columns.UUID(partition_key=True, default=uuid4) cluster = columns.Integer(partition_key=True) count = columns.Integer() text = columns.Text(partition_key=True) float = columns.Float(partition_key=True) text_2 = columns.Text()
class AllDatatypes(UserType): a = columns.Ascii() b = columns.BigInt() c = columns.Blob() d = columns.Boolean() e = columns.DateTime() f = columns.Decimal() g = columns.Double() h = columns.Float() i = columns.Inet() j = columns.Integer() k = columns.Text() l = columns.TimeUUID() m = columns.UUID() n = columns.VarInt()
class AllDatatypesModel(Model): id = columns.Integer(primary_key=True) a = columns.Ascii() b = columns.BigInt() c = columns.Blob() d = columns.Boolean() e = columns.DateTime() f = columns.Decimal() g = columns.Double() h = columns.Float() i = columns.Inet() j = columns.Integer() k = columns.Text() l = columns.TimeUUID() m = columns.UUID() n = columns.VarInt()
country_code = columns.Text(min_length=3, max_length=3) # A list of specialties of the company specialties = columns.List(value_type=columns.Text) # A field that represent a map of key-value # We use caravaggio KeyEncodedMap that appends the field name # to each of the keys in order to make them indexable by the # Search Indexer. websites = KeyEncodedMap( key_type=columns.Text, value_type=columns.Text) # A field that represents a raw JSON content extra_data = columns.Text() latitude = columns.Float() longitude = columns.Float() coordinates = columns.Text() class Meta: get_pk_field = "_id" def validate(self): super().validate() if self.situation not in SITUATIONS: raise ValidationError( "Invalid situation [{0}]. Valid situations are: {1}.". format(self.situation, SITUATIONS))
class Company(CustomDjangoCassandraModel): """ A public traded company """ __table_name__ = "company" # A unique identifier of the entity _id = columns.UUID(partition_key=True, default=uuid.uuid4) # The owner of the data. Who own's the company data persisted user = columns.Text(primary_key=True) # When was created the entity and the last modification date created_at = columns.DateTime(default=datetime.utcnow) updated_at = columns.DateTime(default=datetime.utcnow) # Controls if the entity is active or has been deleted is_deleted = columns.Boolean(default=False) deleted_reason = columns.Text() # The name of the company name = columns.Text(required=True) # A short description about the company short_description = columns.Text() # The company domain (e.g. preseries.com) domain = columns.Text(max_length=50) # The date when the company was founded foundation_date = columns.Date() # The date of the latest funding round last_round = columns.Date() # The total number of funding rounds round_notes = columns.Text() # Country of the company # ISO 3166-1 alpha 3 code country_code = columns.Text(min_length=3, max_length=3) # The stock trading symbol stock_symbol = columns.Text() # Contact email of the company contact_email = columns.Text() # The IDs of the founders of the company founders = columns.List(value_type=columns.UUID) # Address of the headquarters of the company address = UserDefinedType(Address) # A list of specialties of the company specialties = columns.List(value_type=columns.Text) # The counters of the latest followers in twitter # (example of list of integers) latest_twitter_followers = columns.List(value_type=columns.Integer) # A field that represent a map of key-value # We use caravaggio KeyEncodedMap that appends the field name # to each of the keys in order to make them indexable by the # Search Indexer. websites = KeyEncodedMap(key_type=columns.Text, value_type=columns.Text) # A field that represents a raw JSON with the crawler configurations, each # key is a reference to a crawler crawler_config = columns.Text() # A field that represents a raw JSON content extra_data = columns.Text() latitude = columns.Float() longitude = columns.Float() coordinates = columns.Text() class Meta: get_pk_field = '_id' def validate(self): super(Company, self).validate() if self.name == "test": raise ValidationError('The company name cannot be test')
class FloatingPointModel(Model): id = columns.Integer(primary_key=True) f = columns.Float() d = columns.Double()
class ApiAccess(CustomDjangoCassandraModel): """ A model to persist all the access made through the API """ __table_name__ = "caravaggio_api_access" year_month = columns.Text(partition_key=True) """ The combination of year and month for the timestamp associated with the request. Ex. 201901. We use this field as row keys. Each row will contain the access logs made during the month """ time_ms = columns.Integer(primary_key=True, clustering_order="DESC") """ Microseconds (to sort data within one row). """ id = columns.UUID(primary_key=True, default=uuid.uuid4) """ Monotonous UUID(NOT time - based UUID1) """ user = columns.UUID(required=True) """ The user that made the request. """ created_at = columns.DateTime(default=timezone.now) """ When was created the entity and the last modification date""" remote_address = InetAddress(required=True, index=True) """ The IP address of the user doing the request """ server_hostname = columns.Text(required=True) """ The name of the host that is processing the request """ request_method = columns.Text(required=True) """ The method of the request """ request_path = columns.Text(required=True) """ The absolute path of the request """ request_query_params = KeyEncodedMap(key_type=columns.Text, value_type=columns.Text) """ We save all the query params informed in the request as a map. We use caravaggio KeyEncodedMap that appends the field name to each of the keys in order to make them indexable by the Search Indexer. """ request_body = columns.Bytes(required=True) """ The body of the request made by the user""" response_status = columns.SmallInt(required=True) response_body = columns.Text(required=True) """ The JSON the server responded to the client. If the response is not a JSON response, the body will be replaced by a <<<Streaming>>> text if the request is in steamming, or <<<Not JSON>>> in other case. """ run_time = columns.Integer(required=True) latitude = columns.Float() longitude = columns.Float() coordinates = columns.Text() class Meta: get_pk_field = "year_month" def validate(self): super(ApiAccess, self).validate()