Search in sources :

Example 16 with GridQueryFieldMetadata

use of org.apache.ignite.internal.processors.query.GridQueryFieldMetadata in project ignite by apache.

the class IgniteCacheAbstractFieldsQuerySelfTest method testExecuteWithMetaDataAndPrecision.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
@Test
public void testExecuteWithMetaDataAndPrecision() throws Exception {
    QueryEntity qeWithPrecision = new QueryEntity().setKeyType("java.lang.Long").setValueType("TestType").addQueryField("strField", "java.lang.String", "strField").setFieldsPrecision(ImmutableMap.of("strField", 999));
    grid(0).getOrCreateCache(cacheConfiguration().setName("cacheWithPrecision").setQueryEntities(Collections.singleton(qeWithPrecision)));
    GridQueryProcessor qryProc = grid(0).context().query();
    qryProc.querySqlFields(new SqlFieldsQuery("INSERT INTO TestType(_KEY, strField) VALUES(?, ?)").setSchema("cacheWithPrecision").setArgs(1, "ABC"), true);
    qryProc.querySqlFields(new SqlFieldsQuery("INSERT INTO TestType(_KEY, strField) VALUES(?, ?)").setSchema("cacheWithPrecision").setArgs(2, "DEF"), true);
    QueryCursorImpl<List<?>> cursor = (QueryCursorImpl<List<?>>) qryProc.querySqlFields(new SqlFieldsQuery("SELECT _KEY, strField FROM TestType").setSchema("cacheWithPrecision"), true);
    List<GridQueryFieldMetadata> fieldsMeta = cursor.fieldsMeta();
    for (GridQueryFieldMetadata meta : fieldsMeta) {
        if (!meta.fieldName().equalsIgnoreCase("strField"))
            continue;
        assertEquals(999, meta.precision());
    }
}
Also used : GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) GridQueryFieldMetadata(org.apache.ignite.internal.processors.query.GridQueryFieldMetadata) ArrayList(java.util.ArrayList) List(java.util.List) QueryEntity(org.apache.ignite.cache.QueryEntity) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 17 with GridQueryFieldMetadata

use of org.apache.ignite.internal.processors.query.GridQueryFieldMetadata in project ignite by apache.

the class ParameterTypeInferenceTest method check.

/**
 * Execute query.
 *
 * @param qry Query.
 * @param loc Local flag.
 */
private void check(String qry, boolean loc) {
    List<Object[]> argss = new ArrayList<>();
    argss.add(new Object[] { null });
    argss.add(new Object[] { "STRING" });
    argss.add(new Object[] { 1 });
    argss.add(new Object[] { 1L });
    argss.add(new Object[] { new BigDecimal("12.12") });
    argss.add(new Object[] { UUID.randomUUID() });
    clearParserCache();
    for (int i = 0; i < argss.size(); i++) {
        for (Object[] args : argss) {
            for (int j = 0; j < 2; j++) {
                SqlFieldsQuery qry0 = new SqlFieldsQuery(qry).setLocal(loc).setArgs(args);
                try (QueryCursorEx<List<?>> cur = (QueryCursorEx<List<?>>) grid(0).cache(CACHE_NAME).query(qry0)) {
                    GridQueryFieldMetadata meta = cur.fieldsMeta().get(0);
                    cur.getAll();
                    String errMsg = "Failure on i=" + i + ", j=" + j + ": " + meta.fieldTypeName();
                    assertEquals(errMsg, Object.class.getName(), meta.fieldTypeName());
                }
            }
        }
        argss.add(argss.remove(0));
    }
}
Also used : QueryCursorEx(org.apache.ignite.internal.processors.cache.query.QueryCursorEx) ArrayList(java.util.ArrayList) GridQueryFieldMetadata(org.apache.ignite.internal.processors.query.GridQueryFieldMetadata) ArrayList(java.util.ArrayList) List(java.util.List) BigDecimal(java.math.BigDecimal) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

GridQueryFieldMetadata (org.apache.ignite.internal.processors.query.GridQueryFieldMetadata)17 ArrayList (java.util.ArrayList)11 List (java.util.List)10 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 SQLException (java.sql.SQLException)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 PreparedStatement (java.sql.PreparedStatement)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Prepared (org.h2.command.Prepared)4 Test (org.junit.Test)4 Connection (java.sql.Connection)3 UUID (java.util.UUID)3 IgniteException (org.apache.ignite.IgniteException)3 QueryEntity (org.apache.ignite.cache.QueryEntity)3 GridCacheTwoStepQuery (org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery)3 QueryCursorEx (org.apache.ignite.internal.processors.cache.query.QueryCursorEx)3 GridQueryProcessor (org.apache.ignite.internal.processors.query.GridQueryProcessor)3 GridH2QueryContext (org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext)3 BigDecimal (java.math.BigDecimal)2