An extension of postgresql, top-k-dominating query of incomplete database.
- Please refer to Dr. Gao's paper: Top-k Dominating Queries on Incomplete Data
- Operating system: Mac OSX / Ubuntu 14.04
- PostgreSQL version: PostgreSQL 9.3
For Ubuntu:
sudo apt-get install postgresql-9.3
sudo apt-get install postgresql-contrib-9.3
sudo apt-get install postgresql-server-dev-9.3
For Mac:
brew install postgresql
git clone git@github.com:iykon/top-k-dominating.git
cd top-k-dominating
In terminal, you will find the "tkd.sql" followed by a contrib path. Example:
"/usr/share/postgresql/9.3/contrib"
(1) Log into postgres with the database that you want to add function to.
(If you want to add function to all database, log into template1 database. More details can be found here)
(2) Use postgresql command to import function. Example:
\i /usr/share/postgresql/9.3/contrib/tkd.sql
(3) If everything is fine, two "CREATE FUNCTION" should be outputed.
Here is a database sample given in the paper:
postgres=> select * from tkd;
name | d1 | d2 | d3 | d4
------+----+----+----+----
B3 | | | 4 | 9
D2 | 2 | 1 | | 4
C2 | 2 | | | 1
B2 | | | 3 | 1
C4 | 3 | | | 3
A2 | | 1 | 2 | 1
D5 | 5 | 5 | | 4
D1 | 3 | 5 | | 2
D3 | 2 | 4 | | 1
B1 | | | 1 | 2
C1 | 2 | | | 3
A4 | | 7 | 4 | 5
C3 | 3 | | | 2
B5 | | | 7 | 4
C5 | 3 | | | 4
A3 | | 1 | 3 | 4
A5 | | 4 | 8 | 3
B4 | | | 3 | 7
A1 | | 3 | 1 | 3
D4 | 4 | 4 | | 5
(20 rows)
Now since we have created tkd function in the server, we can run tkd query in the following format:
postgres=> select * from tkd('select name,d1,d2,d3,d4 from tkd',3,0) as (name text,d1 int, d2 int, d3 int, d4 int);
name | d1 | d2 | d3 | d4
------+----+----+----+----
C2 | 2 | | | 1
A2 | | 1 | 2 | 1
B2 | | | 3 | 1
(3 rows)
Note that tkd function needs three parameters:
- The selection clause (text type)
- This clause can not be NULL.
- K (integer type)
- Rows to output.
- Dominating method (integer type)
- 0 indicates a dominates b if a is smaller than b.
- Non-zero number indicates a dominates b if a is larger than b.
- This parameter is optional and the default value is zero.
(ps: you should also provide the output format using as clause, otherwise it won't work).
- If you have any question about this paper, you can contact Dr. Gao: gaoyj@zju.edu.cn
- The projet is coded by Weida Pan (Iykon), feel free to ask any questions: iykoncoc001@gmail.com