Creating an optimized store
There are multiple ways to create an optimized store with DB2. The
migration scenario in Part 1 uses the
createrdfstoreandloader command to create
an optimized store. This does bulk loading of RDF data into a
DB2 database. In the case of bulk loading, it is expected that the
input data has a good sampling of how predicates correlate across the
different resource types. However, you might begin application development without having
representative data to create an optimized store. In this case, you
have two options:
- Start by creating a default store, as in Part 1, and use it until you generate sufficient data — in the system QA cycle for the application, for example. You can then have the DB2 database engine calculate the predicate correlation for the default store and use this correlation information to create an optimized store for production. We will walk you through this mechanism here in Part 2.
- Start by creating a default store and use the
REORGfamily of DB2 RDF commands to reorganize the store into an optimized store. For more information, see the DB2 Information Center topic titled "Converting a default store to an optimized store" (see Resources).
To use predicate correlation to recreate the default staffing store you created in Part 1 as an optimized store:
- Using the existing store, generate predicate mappings.
- Create the optimized store by using the predicate mappings.
A predicate mapping is a mapping between a predicate in the data set and the column in the underlying relational table of the DB2 RDF store in which the predicate will be stored. A predicate mapping is determined based on the correlation of the predicate among the various RDF resource types on which it occurs. This is done to pack the RDF data in the fewest number of columns.
Java™ class generates the predicate mapping for a default store and
prints the mapping to the console. The syntax for the method is as
java com.ibm.rdf.store.cmd.GeneratePredicateMappings RDF_store_name -db database_name -user user_name -password user_password [ -host host_name ] [ -port port_number ] [ -schema schema_name ]
The program resources for this tutorial are in the DB2RDFTutorial-Part2.zip file (see Downloads). Please follow the steps described in the section "Setting up the RDF application development environment" in Part 1 to import the Java project DB2RDFTutorial-Part2.
You can run
GeneratePredicatesMappings at the command prompt by
using the genpredicatemappings.bat file available in the
resources folder of the DB2RDFTutorial-Part2.zip file (see Downloads). Copy genpredicatemappings.bat to the <DB install
location>\SQLLIB\rdf\bin folder and run it from there by passing
all the required arguments as follows. You should direct the
output of this command to a file:
C:\Program Files\IBM\SQLLIB\rdf\bin>genpredicatemappings.bat staffing -db RDFSAMPL -user db2admin -password db2admin > /predicate_mappings.txt
To run it inside IBM Data Studio, you can use the GeneratePredicateMappings.launch
configuration file in the DB2RDFTutorial-Part 2 project to call the
class to generate the predicate mapping for the default staffing
store. The output is printed to the console and written to the
staffing_predicate_mappings.txt file. The output is saved so you
can use it in the next step, in which you create an optimized
To generate the mappings by using the launch configuration:
- Open IBM Data Studio.
Figure 1. The launch application in IBM Data Studio
Optional: Change the location of the output file by right-clicking the GeneratePredicateMappings.launch configuration file and selecting Run As > Run Configurations.
Figure 2. Run Configurations view to change the location
Click Close to close this window.
- Right-click the launch configuration and click Run As > GeneratePredicateMappings. The predicate mapping is generated, printed to the console, and written to the specified file.
To create an optimized store:
- Issue the
createrdfstorecommand, using the
–predicatemappingsparameter to specify the location of the predicate mapping you generated. In this tutorial, issue the
createrdfstorecommand as follows:
C:\Program Files\IBM\SQLLIB\rdf\bin>createrdfstore staffing_optimized -db RDFSAMPL -user db2admin -password db2admin –predicatemappings \ staffing_predicate_mappings.txt
- Load the data into the optimized store. You can use the
InsertGraph.java sample program, described in Part 1. Because you specified the
name of the store in the previous step as
staffing_optimized, you must modify line 44 of the InsertGraph.java program as follows:
String storeName = "staffing_optimized";
The InsertGraph.java program inserts the triples successfully into the optimized store. This indicates that any application you build to use a default store will work with an optimized store, without any code changes.