Example #1
0
def window_aggregate_schema(schema_loader_with_mem_store: SchemaLoader, mem_store_name: str,
                            stream_dtc_name: str) -> WindowAggregateSchema:
    schema_loader_with_mem_store.add_schema_spec({
        'Type': Type.BLURR_AGGREGATE_BLOCK,
        'Name': 'session',
        'Store': mem_store_name,
        'Fields': [
            {
                'Name': 'events',
                'Type': Type.INTEGER,
                'Value': 'session.events + 1',
            },
        ],
    }, stream_dtc_name)
    name = schema_loader_with_mem_store.add_schema_spec({
        'Type': Type.BLURR_AGGREGATE_WINDOW,
        'Name': 'test_window_name',
        'WindowType': Type.DAY,
        'WindowValue': 1,
        'Source': stream_dtc_name + '.session',
        'Fields': [{
            'Name': 'total_events',
            'Type': Type.INTEGER,
            'Value': 'sum(source.events)'
        }]
    })

    return WindowAggregateSchema(name, schema_loader_with_mem_store)
def test_initialization_with_invalid_source(
        schema_loader_with_mem_store: SchemaLoader,
        window_schema_spec: Dict[str, Any], stream_dtc_name: str):
    name = schema_loader_with_mem_store.add_schema_spec(window_schema_spec)

    with raises(GenericSchemaError,
                match=stream_dtc_name + '.session not declared in schema'):
        WindowAggregateSchema(name, schema_loader_with_mem_store)
def test_initialization_with_invalid_source(
        schema_loader_with_mem_store: SchemaLoader,
        window_schema_spec: Dict[str, Any]):
    name = schema_loader_with_mem_store.add_schema_spec(window_schema_spec)

    schema = WindowAggregateSchema(name, schema_loader_with_mem_store)
    assert len(schema.errors) == 0
    assert len(schema_loader_with_mem_store.get_errors()) == 0
def test_initialization_with_valid_source(
        schema_loader_with_mem_store: SchemaLoader,
        aggregate_block_schema_spec: Dict[str, Any],
        window_schema_spec: Dict[str, Any], stream_dtc_name: str):
    schema_loader_with_mem_store.add_schema_spec(aggregate_block_schema_spec,
                                                 stream_dtc_name)
    name = schema_loader_with_mem_store.add_schema_spec(window_schema_spec)

    window_aggregate_schema = WindowAggregateSchema(
        name, schema_loader_with_mem_store)
    assert Type.is_type_equal(window_aggregate_schema.window_type, Type.DAY)
    assert window_aggregate_schema.window_value == 1
    assert isinstance(window_aggregate_schema.source, BlockAggregateSchema)
    assert window_aggregate_schema.source.name == 'session'
def test_window_aggregate_schema_missing_attributes_adds_error(
        schema_loader_with_mem_store: SchemaLoader,
        aggregate_block_schema_spec: Dict[str, Any],
        window_schema_spec: Dict[str, Any], stream_dtc_name: str):
    del window_schema_spec[WindowAggregateSchema.ATTRIBUTE_WINDOW_TYPE]
    del window_schema_spec[WindowAggregateSchema.ATTRIBUTE_WINDOW_VALUE]
    del window_schema_spec[WindowAggregateSchema.ATTRIBUTE_SOURCE]

    schema_loader_with_mem_store.add_schema_spec(aggregate_block_schema_spec,
                                                 stream_dtc_name)
    name = schema_loader_with_mem_store.add_schema_spec(window_schema_spec)

    schema = WindowAggregateSchema(name, schema_loader_with_mem_store)

    assert 3 == len(schema.errors)
    assert isinstance(schema.errors[0], RequiredAttributeError)
    assert WindowAggregateSchema.ATTRIBUTE_WINDOW_TYPE == schema.errors[
        0].attribute
Example #6
0
def window_aggregate_schema(request,
                            schema_loader_with_mem_store: SchemaLoader,
                            mem_store_name: str,
                            stream_bts_name: str) -> WindowAggregateSchema:
    schema_loader_with_mem_store.add_schema_spec(
        {
            'Type':
            Type.BLURR_AGGREGATE_ACTIVITY,
            'Name':
            'session',
            'Store':
            mem_store_name,
            'SeparateByInactiveSeconds':
            1800,
            'Fields': [
                {
                    'Name': 'events',
                    'Type': Type.INTEGER,
                    'Value': 'session.events + 1',
                },
            ],
        }, stream_bts_name)
    schema_loader_with_mem_store.add_schema_spec(
        {
            'Type':
            Type.BLURR_AGGREGATE_BLOCK,
            'Name':
            'session_dim',
            'Store':
            mem_store_name,
            'Dimensions:': [
                {
                    'Name': 'custom_dimension',
                    'Type': Type.STRING,
                    'Value': 'session.dim',
                },
                {
                    'Name': 'session_id',
                    'Type': Type.STRING,
                    'Value': 'session.session_id',
                },
            ],
            'Fields': [
                {
                    'Name': 'events',
                    'Type': Type.INTEGER,
                    'Value': 'session.events + 1',
                },
            ],
        }, stream_bts_name)
    name = schema_loader_with_mem_store.add_schema_spec({
        'Type':
        Type.BLURR_AGGREGATE_WINDOW,
        'Name':
        'test_window_name',
        'WindowType':
        Type.DAY,
        'WindowValue':
        1,
        'Source':
        stream_bts_name +
        ('.session' if request.param == 'activity' else '.session_dim'),
        'Fields': [{
            'Name': 'total_events',
            'Type': Type.INTEGER,
            'Value': 'sum(source.events)'
        }]
    })

    return WindowAggregateSchema(name, schema_loader_with_mem_store)