Schema and Indexes
This is a legacy Apache Ignite documentation
The new documentation is hosted here: https://ignite.apache.org/docs/latest/
In addition to common DDL commands, C++ developers can use special SQL APIs for schema and indexes definition:
QueryEntity Based Configuration
Indexes and fields can be configured with org.apache.ignite.cache.QueryEntity
which is convenient for XML configuration with Spring.
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="mycache"/>
<!-- Configure query entities -->
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.lang.Long"/>
<property name="valueType" value="Person"/>
<property name="fields">
<map>
<entry key="id" value="java.lang.Long"/>
<entry key="orgId" value="java.lang.Long"/>
<entry key="firstName" value="java.lang.String"/>
<entry key="lastName" value="java.lang.String"/>
<entry key="resume" value="java.lang.String"/>
<entry key="salary" value="java.lang.Double"/>
</map>
</property>
<property name="indexes">
<list>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="id"/>
</bean>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="orgId"/>
</bean>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="salary"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
Updating Indexes and Queryable Fields at Runtime
Use ALTER TABLE, CREATE/DROP INDEX commands if it's needed to manage indexes or make new fields of the object visible to SQL engine at runtime.
Custom Keys
If you use only predefined SQL data types for primary keys, then there is no need to perform additional manipulation with DML related configuration.
Predefined SQL Data Types
- all the signed integral types
bool
,float
double
std::string
ignite::Timestamp
ignite::Date
ignite::Guid
int8_t[]
However, once you decide to introduce a custom complex key and refer to its fields from DML statements, you have to set QueryField.IsKeyField
to true
in QueryEntity
configuration.
<cacheConfiguration name="cars">
<queryEntities>
<queryEntity keyTypeName="CarKey" valueTypeName="Car">
<fields>
<queryField fieldType="System.String" fieldTypeName="java.lang.String" isKeyField="true" name="VIN" />
<queryField fieldType="System.Int32" fieldTypeName="java.lang.Integer" isKeyField="true" name="Id" />
<queryField fieldType="System.String" fieldTypeName="java.lang.String" name="Make" />
<queryField fieldType="System.Int32" fieldTypeName="java.lang.Integer" name="Year" />
</fields>
</queryEntity>
</queryEntities>
</cacheConfiguration>
Updated over 4 years ago