def create_ad_hoc_field(cls, db_type): import infi.clickhouse_orm.fields as orm_fields # Enums if db_type.startswith('Enum'): db_type = 'String' # enum.Eum is not comparable # Arrays if db_type.startswith('Array'): inner_field = cls.create_ad_hoc_field(db_type[6:-1]) return orm_fields.ArrayField(inner_field) # FixedString if db_type.startswith('FixedString'): db_type = 'String' if db_type == 'LowCardinality(String)': db_type = 'String' if db_type.startswith('DateTime'): db_type = 'DateTime' if db_type.startswith('Nullable'): inner_field = cls.create_ad_hoc_field(db_type[9:-1]) return orm_fields.NullableField(inner_field) # db_type for Deimal comes like 'Decimal(P, S) string where P is precision and S is scale' if db_type.startswith('Decimal'): nums = [int(n) for n in db_type[8:-1].split(',')] return orm_fields.DecimalField(nums[0], nums[1]) # Simple fields name = db_type + 'Field' if not hasattr(orm_fields, name): raise NotImplementedError('No field class for %s' % db_type) return getattr(orm_fields, name)()
def create_ad_hoc_field(cls, db_type): import infi.clickhouse_orm.fields as orm_fields # Enums if db_type.startswith('Enum'): return orm_fields.BaseEnumField.create_ad_hoc_field(db_type) # DateTime with timezone if db_type.startswith('DateTime('): # Some functions return DateTimeField with timezone in brackets return orm_fields.DateTimeField() # Arrays if db_type.startswith('Array'): inner_field = cls.create_ad_hoc_field(db_type[6:-1]) return orm_fields.ArrayField(inner_field) # FixedString if db_type.startswith('FixedString'): length = int(db_type[12:-1]) return orm_fields.FixedStringField(length) # Decimal if db_type.startswith('Decimal'): precision, scale = [ int(n.strip()) for n in db_type[8:-1].split(',') ] return orm_fields.DecimalField(precision, scale) # Nullable if db_type.startswith('Nullable'): inner_field = cls.create_ad_hoc_field(db_type[9:-1]) return orm_fields.NullableField(inner_field) # Simple fields name = db_type + 'Field' if not hasattr(orm_fields, name): raise NotImplementedError('No field class for %s' % db_type) return getattr(orm_fields, name)()
def create_ad_hoc_field(cls, db_type): import infi.clickhouse_orm.fields as orm_fields # Enums if db_type.startswith('Enum'): db_type = 'String' # enum.Eum is not comparable # Arrays if db_type.startswith('Array'): inner_field = cls.create_ad_hoc_field(db_type[6 : -1]) return orm_fields.ArrayField(inner_field) # FixedString if db_type.startswith('FixedString'): db_type = 'String' # DateTime if db_type.startswith('DateTime'): db_type = 'DateTime' if db_type.startswith('Nullable'): inner_field = cls.create_ad_hoc_field(db_type[9 : -1]) return orm_fields.NullableField(inner_field) # Simple fields name = db_type + 'Field' if not hasattr(orm_fields, name): raise NotImplementedError('No field class for %s' % db_type) return getattr(orm_fields, name)()
class ClickhouseAllFields(chm.Model): id = chf.Int64Field() timestamp = chf.DateTimeField() timestamp_date = chf.DateField() string_field = chf.StringField() intfield = chf.Int32Field() floatfield = chf.Float32Field() null_field = chf.NullableField(chf.StringField()) enum_field = chf.Enum16Field(enum_) array_field = chf.ArrayField(chf.Int16Field()) engine = MergeTree('timestamp_date', ['id'])
def create_ad_hoc_field(cls, db_type): import infi.clickhouse_orm.fields as orm_fields # Enums if db_type.startswith('Enum'): return orm_fields.BaseEnumField.create_ad_hoc_field(db_type) # DateTime with timezone if db_type.startswith('DateTime('): timezone = db_type[9:-1] return orm_fields.DateTimeField( timezone=timezone[1:-1] if timezone else None ) # DateTime64 if db_type.startswith('DateTime64('): precision, *timezone = [s.strip() for s in db_type[11:-1].split(',')] return orm_fields.DateTime64Field( precision=int(precision), timezone=timezone[0][1:-1] if timezone else None ) # Arrays if db_type.startswith('Array'): inner_field = cls.create_ad_hoc_field(db_type[6 : -1]) return orm_fields.ArrayField(inner_field) # Tuples (poor man's version - convert to array) if db_type.startswith('Tuple'): types = [s.strip() for s in db_type[6 : -1].split(',')] assert len(set(types)) == 1, 'No support for mixed types in tuples - ' + db_type inner_field = cls.create_ad_hoc_field(types[0]) return orm_fields.ArrayField(inner_field) # FixedString if db_type.startswith('FixedString'): length = int(db_type[12 : -1]) return orm_fields.FixedStringField(length) # Decimal / Decimal32 / Decimal64 / Decimal128 if db_type.startswith('Decimal'): p = db_type.index('(') args = [int(n.strip()) for n in db_type[p + 1 : -1].split(',')] field_class = getattr(orm_fields, db_type[:p] + 'Field') return field_class(*args) # Nullable if db_type.startswith('Nullable'): inner_field = cls.create_ad_hoc_field(db_type[9 : -1]) return orm_fields.NullableField(inner_field) # LowCardinality if db_type.startswith('LowCardinality'): inner_field = cls.create_ad_hoc_field(db_type[15 : -1]) return orm_fields.LowCardinalityField(inner_field) # Simple fields name = db_type + 'Field' if not hasattr(orm_fields, name): raise NotImplementedError('No field class for %s' % db_type) return getattr(orm_fields, name)()
def create_ad_hoc_field(cls, db_type): import infi.clickhouse_orm.fields as orm_fields # Enums if db_type.startswith('Enum'): return orm_fields.BaseEnumField.create_ad_hoc_field(db_type) # Arrays if db_type.startswith('Array'): inner_field = cls.create_ad_hoc_field(db_type[6:-1]) return orm_fields.ArrayField(inner_field) # FixedString if db_type.startswith('FixedString'): length = int(db_type[12:-1]) return orm_fields.FixedStringField(length) # Nullable if db_type.startswith('Nullable'): inner_field = cls.create_ad_hoc_field(db_type[9:-1]) return orm_fields.NullableField(inner_field) # Simple fields name = db_type + 'Field' if not hasattr(orm_fields, name): raise NotImplementedError('No field class for %s' % db_type) return getattr(orm_fields, name)()
class InstanceData(models.Model): capacityStatus = fields.NullableField(fields.StringField()) clockSpeedIsUpTo = fields.NullableField(BooleanField()) clockSpeed = fields.NullableField(fields.Float32Field()) #in GHz currentGeneration = fields.NullableField(BooleanField()) dedicatedEbsThroughputIsUpTo = fields.NullableField(BooleanField()) dedicatedEbsThroughput = fields.NullableField( fields.Int32Field()) #in Mbps ebsOptimized = fields.NullableField(BooleanField()) ecuIsVariable = fields.NullableField(BooleanField()) ecu = fields.NullableField(fields.Float32Field()) elasticGraphicsType = fields.NullableField(fields.StringField()) enhancedNetworkingSupported = fields.NullableField(BooleanField()) fromLocation = fields.NullableField(fields.StringField()) fromLocationType = fields.NullableField(fields.StringField()) gpu = fields.NullableField(fields.Int32Field()) gpuMemory = fields.NullableField(fields.StringField()) group = fields.NullableField(fields.StringField()) groupDescription = fields.NullableField(fields.StringField()) instance = fields.NullableField(fields.StringField()) instanceCapacity10xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity12xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity16xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity18xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity24xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity2xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity32xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity4xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity8xlarge = fields.NullableField(fields.Int32Field()) instanceCapacity9xlarge = fields.NullableField(fields.Int32Field()) instanceCapacityLarge = fields.NullableField(fields.Int32Field()) instanceCapacityMedium = fields.NullableField(fields.Int32Field()) instanceCapacityXlarge = fields.NullableField(fields.Int32Field()) instanceFamily = fields.NullableField(fields.StringField()) instanceType = fields.NullableField(fields.StringField()) instanceSKU = fields.NullableField(fields.StringField()) intelAvx2Available = fields.NullableField(BooleanField()) intelAvxAvailable = fields.NullableField(BooleanField()) intelTurboAvailable = fields.NullableField(BooleanField()) licenseModel = fields.NullableField(fields.StringField()) location = fields.NullableField(fields.StringField()) locationType = fields.NullableField(fields.StringField()) maxIopsBurstPerformance = fields.NullableField(fields.StringField()) maxIopsVolume = fields.NullableField(fields.StringField()) maxThroughputVolume = fields.NullableField(fields.StringField()) maxVolumeSize = fields.NullableField(fields.Int32Field()) #in TiB memory = fields.NullableField(fields.Float32Field()) #in GiB networkPerformance = fields.NullableField(fields.StringField()) normalizationSizeFactor = fields.NullableField(fields.Float32Field()) operatingSystem = fields.NullableField(fields.StringField()) operation = fields.NullableField(fields.StringField()) physicalCores = fields.NullableField(fields.Int32Field()) physicalProcessor = fields.NullableField(fields.StringField()) preInstalledSw = fields.NullableField(fields.StringField()) processorArchitecture = fields.NullableField(fields.StringField()) processorFeatures = fields.NullableField(fields.StringField()) productFamily = fields.NullableField(fields.StringField()) provisioned = fields.NullableField(BooleanField()) serviceCode = fields.NullableField(fields.StringField()) serviceName = fields.NullableField(fields.StringField()) storageIsEbsOnly = fields.NullableField(BooleanField()) storageCount = fields.NullableField(fields.Int32Field()) storageCapacity = fields.NullableField(fields.Int32Field()) storageType = fields.NullableField(fields.StringField()) storageMedia = fields.NullableField(fields.StringField()) tenancy = fields.NullableField(fields.StringField()) toLocation = fields.NullableField(fields.StringField()) toLocationType = fields.NullableField(fields.StringField()) transferType = fields.NullableField(fields.StringField()) usageType = fields.NullableField(fields.StringField()) vcpu = fields.NullableField(fields.Int32Field()) volumeType = fields.NullableField(fields.StringField()) onDemandAppliesTo = fields.NullableField(fields.StringField()) onDemandBeginRange = fields.NullableField(fields.StringField()) onDemandDescription = fields.NullableField(fields.StringField()) onDemandEffectiveDate = fields.NullableField(fields.DateTimeField()) onDemandEndRange = fields.NullableField(fields.Float32Field()) onDemandOfferTermCode = fields.NullableField(fields.StringField()) onDemandRateCode = fields.NullableField(fields.StringField()) onDemandPricePerUnit = fields.NullableField(fields.StringField()) onDemandPriceUnit = fields.NullableField(fields.StringField()) reservedAppliesTo = fields.NullableField(fields.StringField()) reservedBeginRange = fields.NullableField(fields.StringField()) reservedDescription = fields.NullableField(fields.StringField()) reservedEffectiveDate = fields.NullableField(fields.StringField()) reservedEndRange = fields.NullableField(fields.StringField()) reservedLeaseContractLength = fields.NullableField(fields.StringField()) reservedOfferTermCode = fields.NullableField(fields.StringField()) reservedOfferingClass = fields.NullableField(fields.StringField()) reservedPurchaseOption = fields.NullableField(fields.StringField()) reservedRateCode = fields.NullableField(fields.StringField()) reservedPricePerUnit = fields.NullableField(fields.StringField()) reservedPriceUnit = fields.NullableField(fields.StringField()) spotPrice = fields.NullableField(fields.StringField()) spotTimestamp = fields.NullableField(fields.StringField()) spotInstanceType = fields.NullableField(fields.StringField()) spotAvailabilityZone = fields.NullableField(fields.StringField()) engine = engines.Memory()
class Event(models.Model): t = fields.Enum8Field(EventType) tid = fields.StringField() cid = fields.NullableField(fields.UUIDField()) cn = fields.StringField() cf1 = fields.NullableField(fields.StringField()) cf2 = fields.NullableField(fields.StringField()) cf3 = fields.NullableField(fields.StringField()) cf4 = fields.NullableField(fields.StringField()) cf5 = fields.NullableField(fields.StringField()) dl = fields.NullableField(fields.StringField()) dr = fields.NullableField(fields.StringField()) uip = fields.NullableField(fields.StringField()) utt = fields.NullableField(fields.StringField()) ua = fields.NullableField(fields.StringField()) # Event fields # (Required for event type) ec = fields.NullableField(fields.StringField()) ea = fields.NullableField(fields.StringField()) el = fields.NullableField(fields.StringField()) ev = fields.NullableField(fields.Int64Field()) # Transaction fields # (Required for transaction type) ti = fields.NullableField(fields.StringField()) tr = fields.NullableField(fields.Decimal64Field(scale=6)) # Revenue fields r = fields.NullableField(fields.Decimal64Field(scale=6)) event_time = fields.DateTimeField() event_date = fields.DateField(materialized="toDate(event_time)") engine = engines.MergeTree("event_date", ("tid", "event_date")) @classmethod def table_name(cls): return "events"