def test_schema(self): project_name_0 = "topic_test_p%d_0" % int(time.time()) topic_name_0 = "topic_test_t%d_0" % int(time.time()) topic_name_1 = "topic_test_t%d_1" % int(time.time()) shard_count = 3 life_cycle = 7 record_schema_0 = RecordSchema.from_lists( ['bigint_field', 'string_field', 'double_field', 'bool_field', 'event_time1'], [FieldType.BIGINT, FieldType.STRING, FieldType.DOUBLE, FieldType.BOOLEAN, FieldType.TIMESTAMP]) record_schema_1 = RecordSchema() record_schema_1.add_field(Field('bigint_field', FieldType.BIGINT)) record_schema_1.add_field(Field('string_field', FieldType.STRING, False)) record_schema_1.add_field(Field('double_field', FieldType.DOUBLE, False)) record_schema_1.add_field(Field('bool_field', FieldType.BOOLEAN)) record_schema_1.add_field(Field('event_time1', FieldType.TIMESTAMP)) print(record_schema_0) print(RecordSchema()) try: dh.create_project(project_name_0, '') except ResourceExistException: pass # make sure project wil be deleted try: try: dh.create_tuple_topic(project_name_0, topic_name_0, shard_count, life_cycle, record_schema_0, '') except ResourceExistException: pass result = dh.get_topic(project_name_0, topic_name_0) print(result) for index, field in enumerate(result.record_schema.field_list): assert field.name == record_schema_0.field_list[index].name assert field.type == record_schema_0.field_list[index].type assert field.allow_null == record_schema_0.field_list[index].allow_null try: dh.create_tuple_topic(project_name_0, topic_name_1, shard_count, life_cycle, record_schema_1, '') except ResourceExistException: pass result = dh.get_topic(project_name_0, topic_name_1) print(result) for index, field in enumerate(result.record_schema.field_list): assert field.name == record_schema_1.field_list[index].name assert field.type == record_schema_1.field_list[index].type assert field.allow_null == record_schema_1.field_list[index].allow_null finally: clean_topic(dh, project_name_0) dh.delete_project(project_name_0)
def test_build_schema_success(self): record_schema_0 = RecordSchema.from_lists([ 'bigint_field', 'string_field', 'double_field', 'bool_field', 'event_time1' ], [ FieldType.BIGINT, FieldType.STRING, FieldType.DOUBLE, FieldType.BOOLEAN, FieldType.TIMESTAMP ], [False, True, True, True, True]) record_schema_1 = RecordSchema([]) record_schema_1.add_field( Field('bigint_field', FieldType.BIGINT, False)) record_schema_1.add_field(Field('string_field', FieldType.STRING)) record_schema_1.add_field(Field('double_field', FieldType.DOUBLE)) record_schema_1.add_field(Field('bool_field', FieldType.BOOLEAN)) record_schema_1.add_field(Field('event_time1', FieldType.TIMESTAMP)) fields = [] fields.append(Field('bigint_field', FieldType.BIGINT, False)) fields.append(Field('string_field', FieldType.STRING)) fields.append(Field('double_field', FieldType.DOUBLE)) fields.append(Field('bool_field', FieldType.BOOLEAN)) fields.append(Field('event_time1', FieldType.TIMESTAMP)) record_schema_2 = RecordSchema(fields) for index in range(0, len(record_schema_0.field_list)): assert record_schema_0.field_list[ index].name == record_schema_1.field_list[index].name assert record_schema_0.field_list[ index].type == record_schema_1.field_list[index].type assert record_schema_0.field_list[ index].allow_null == record_schema_1.field_list[ index].allow_null assert record_schema_0.field_list[ index].name == record_schema_2.field_list[index].name assert record_schema_0.field_list[ index].type == record_schema_2.field_list[index].type assert record_schema_0.field_list[ index].allow_null == record_schema_2.field_list[ index].allow_null
def test_build_schema_with_invalid_type(self): try: record_schema_0 = RecordSchema.from_lists([ 'bigint_field', 'string_field', 'double_field', 'bool_field', 'event_time1' ], [ 'int', FieldType.STRING, FieldType.DOUBLE, FieldType.BOOLEAN, FieldType.TIMESTAMP ]) except InvalidParameterException: pass else: raise Exception('build schema success with wrong filed type!') try: record_schema_1 = RecordSchema() record_schema_1.add_field(Field('string_field', 'str')) except InvalidParameterException: pass else: raise Exception('build schema success with wrong filed type!') try: fields = [] fields.append(Field('bigint_field', FieldType.BIGINT)) fields.append(Field('string_field', FieldType.STRING)) fields.append(Field('double_field', FieldType.DOUBLE)) fields.append(Field('bool_field', FieldType.BOOLEAN)) fields.append(Field('event_time1', 'time')) except InvalidParameterException: pass else: raise Exception('build schema success with wrong filed type!')
retry_times=args.retry_times, conn_timeout=args.conn_timeout, read_timeout=args.read_timeout) #project = Project(name=args.project, comment='perf project for python sdk') #dh.create_project(project) #print "create project %s success!" % args.project #print "=======================================\n\n" data = 'a' if args.file: with open(args.file, 'r') as f: data = f.read() record_schema = RecordSchema() # record_schema.add_field(Field('bigint_field', FieldType.BIGINT)) record_schema.add_field(Field('string_field', FieldType.STRING)) # record_schema.add_field(Field('double_field', FieldType.DOUBLE)) # record_schema.add_field(Field('bool_field', FieldType.BOOLEAN)) # record_schema.add_field(Field('time_field', FieldType.TIMESTAMP)) # topic = Topic(name=args.topic) topic.project_name = args.project topic.shard_count = 1 topic.life_cycle = 7 topic.record_type = RecordType.TUPLE topic.record_schema = record_schema try: dh.create_topic(topic) print "create topic %s success!" % args.project print "=======================================\n\n"