<?xml version="1.0" encoding="utf-8"?>
<test>

<name>aggregate functions</name>
<requires>
<variant_match />
</requires>

<num_agents>3</num_agents>

<config>
indexer
{
	mem_limit		= 16M
}

searchd
{
	<searchd_settings/>
<dynamic>
<variant>
	dist_threads = 2
</variant>
<variant />
</dynamic>
}

source srctest
{
	type			= mysql
	<sql_settings/>
	sql_query		= SELECT * FROM test_table
	sql_attr_uint	= gid
	sql_attr_float	= price
	sql_attr_uint	= views
}

source srctest2 : srctest
{
	sql_query		= SELECT document_id+10, body, gid, price, views FROM test_table
}

source srctest3 : srctest
{
	sql_query		= SELECT document_id+20, body, gid, price*2 price, views FROM test_table
}

<agent0>
index test
{
	source			= srctest
	path			= <data_path/>/test
	docinfo			= extern
}

index test3
{
	source			= srctest3
	path			= <data_path/>/test3
	docinfo			= extern
}

index dist
{
	type			= distributed
	local			= test
	agent			= <agent_address/>:test2
}

index dist2
{
	type			= distributed
	agent			= <agent1_address/>:test2
	agent			= <agent2_address/>:testr
}
index dist3
{
	type			= distributed
	local			= test
	agent			= <agent_address/>:test2,test4
}


source src10
{
	type			= mysql
	<sql_settings/>
	sql_query = SELECT 1 id, 11 idd, 'ab cd'
	sql_attr_uint	= idd
}

index i10
{
	source			= src10
	path			= <data_path/>/i10
	docinfo			= extern
	dict = keywords
	min_prefix_len = 1
}
index i11
{
	source			= src10
	path			= <data_path/>/i11
	docinfo			= extern
	dict = keywords
	min_prefix_len = 1
}
index i12
{
	source			= src10
	path			= <data_path/>/i12
	docinfo			= extern
	charset_table	= b..z
	dict = keywords
	min_prefix_len = 1
}

</agent0>
<agent1>
index test2
{
	source			= srctest2
	path			= <data_path/>/test2
	docinfo			= extern
}
index test4 : test2
{
	path			= <data_path/>/test4
}
</agent1>
<agent2>
index testr
{
	source			= srctest
	path			= <data_path/>/testr
	docinfo			= extern
}
</agent2>
</config>

<queries>
<query index="test" select="avg(price) as avgprice,gid*10 as xgid" groupattr="gid"/>
<query index="test" select="*,avg(price) as avgprice" groupattr="gid"/>
<query index="test" select="*,sum(views) as sumviews, avg(price) as avgprice" groupattr="gid"/>
<query index="dist" select="*,avg(price) as avgprice" groupattr="gid"/>
<query index="dist" select="*,sum(views) as sumviews, avg(price) as avgprice" groupattr="gid"/>
<query index="dist2" select="*,avg(price) as avgprice" groupattr="gid"/>
<query index="dist2" select="*,sum(views) as sumviews, avg(price) as avgprice" groupattr="gid"/>
<query index="dist3" select="*,avg(price) as avgprice" groupattr="gid"/>
<query index="dist3" select="*,sum(views) as sumviews, avg(price) as avgprice" groupattr="gid"/>
<query index="test" select="gid, sum(views) as sumviews, avg(price) as avgprice" groupattr="gid"/>
<query index="test3" select="gid, sum(views) as sumviews, avg(price) as avgprice" groupattr="gid"/>
<query index="test,test3" select="gid, sum(views) as sumviews, avg(price) as avgprice" groupattr="gid"/>
</queries>

<sphqueries>
<sphinxql>select * from i10 where match('a* abc')</sphinxql>
<sphinxql>show meta</sphinxql>
<sphinxql>select * from i10, i11 where match('a* abc')</sphinxql>
<sphinxql>show meta</sphinxql>
<sphinxql>select * from i11, i10 where match('a* abc')</sphinxql>
<sphinxql>show meta</sphinxql>
<sphinxql>select * from i10, i12 where match('a* abc')</sphinxql>
<sphinxql>show meta</sphinxql>
<sphinxql>select * from i12, i10 where match('a* abc')</sphinxql>
<sphinxql>show meta</sphinxql>
</sphqueries>

<db_create>
CREATE TABLE test_table
(
	document_id		INTEGER NOT NULL PRIMARY KEY,
	body			VARCHAR(255) NOT NULL,
	gid				INTEGER NOT NULL,
	price			FLOAT NOT NULL,
	views			INTEGER NOT NULL
)
</db_create>

<db_drop>
DROP TABLE IF EXISTS test_table
</db_drop>

<db_insert>
INSERT INTO test_table VALUES
( 1, 'dummy', 1, 20.00, 3 ),
( 2, 'dummy', 1, 15.00, 15 ),
( 3, 'dummy', 1, 10.00, 7 ),
( 4, 'dummy', 1, 10.00, 40 )
</db_insert>

</test>
