Search in sources :

Example 31 with Schema

use of org.h2.schema.Schema in project core by s4.

the class AbstractWindowingPE method processEvent.

public void processEvent(Object event) {
    long currentTime = getCurrentTime();
    long maybeCurrentTime = -1;
    if (timestampFields != null) {
        Schema schema = schemaContainer.getSchema(event.getClass());
        String fieldName = timestampFields.get(getStreamName());
        if (fieldName != null) {
            Property property = schema.getProperties().get(fieldName);
            if (property != null && (property.getType().equals(Long.TYPE) || property.getType().equals(Long.class))) {
                try {
                    maybeCurrentTime = (Long) property.getGetterMethod().invoke(event);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
    if (maybeCurrentTime > -1) {
        currentTime = maybeCurrentTime;
        lastTimestamp = currentTime;
    }
    // convert
    long slotTime = slotUtils.getSlotAtTime(currentTime / 1000);
    if (slots == null) {
        slots = Collections.synchronizedMap(new HashMap<Long, Slot>());
    }
    Slot slot = slots.get(slotTime);
    if (slot == null) {
        try {
            slot = (Slot) slotClass.newInstance();
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (InstantiationException ie) {
            throw new RuntimeException(ie);
        }
        slots.put(slotTime, slot);
    }
    overloadDispatcher.dispatch(slot, event, slotTime, this);
}
Also used : HashMap(java.util.HashMap) Schema(io.s4.schema.Schema) Property(io.s4.schema.Schema.Property)

Example 32 with Schema

use of org.h2.schema.Schema in project core by s4.

the class JoinPE method processEvent.

public void processEvent(Object event) {
    if (eventsToJoin == null) {
        eventsToJoin = new HashMap<String, Object>();
    }
    List<String> fieldNames = eventFields.get(getStreamName());
    if (fieldNames == null) {
        return;
    }
    // we only use the last event that comes through on the given stream
    eventsToJoin.put(getStreamName(), event);
    if (eventsToJoin.keySet().size() == eventFields.keySet().size()) {
        Object newEvent = null;
        try {
            newEvent = outputClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        Schema newEventSchema = schemaContainer.getSchema(newEvent.getClass());
        for (String streamName : eventsToJoin.keySet()) {
            Object partialEvent = eventsToJoin.get(streamName);
            Schema partialEventSchema = schemaContainer.getSchema(partialEvent.getClass());
            List<String> includeFields = eventFields.get(streamName);
            if (includeFields.size() == 1 && includeFields.get(0).equals("*")) {
                for (Property partialEventProperty : partialEventSchema.getProperties().values()) {
                    copyField(partialEventProperty.getName(), partialEventSchema, newEventSchema, partialEvent, newEvent);
                }
            } else {
                for (String includeField : includeFields) {
                    copyField(includeField, partialEventSchema, newEventSchema, partialEvent, newEvent);
                }
            }
        }
        dispatcher.dispatchEvent(outputStreamName, newEvent);
        if (logger.isDebugEnabled()) {
            logger.debug("STEP 7 (JoinPE): " + newEvent.toString());
        }
    }
}
Also used : Schema(io.s4.schema.Schema) Property(io.s4.schema.Schema.Property)

Example 33 with Schema

use of org.h2.schema.Schema in project core by s4.

the class DefaultPartitioner method getKeyValues.

private List<KeyInfo> getKeyValues(Object record, Schema schema, List<String> keyNameElements, int elementIndex, List<KeyInfo> keyInfoList, KeyInfo keyInfo) {
    String keyElement = keyNameElements.get(elementIndex);
    Property property = schema.getProperties().get(keyElement);
    if (property == null) {
        return null;
    }
    keyInfo.addElementToPath(keyElement);
    Object value = null;
    try {
        value = property.getGetterMethod().invoke(record);
    } catch (Exception e) {
        if (debug) {
            System.out.println("key element is " + keyElement);
            e.printStackTrace();
        }
    }
    if (value == null) {
        // return a null KeyInfo list if we hit a null value
        return null;
    }
    if (property.isList()) {
        List list = (List) value;
        // TODO: handle case where key does not include property of
        // component type
        Schema componentSchema = property.getComponentProperty().getSchema();
        int listLength = list.size();
        for (int i = 0; i < listLength; i++) {
            Object listEntry = list.get(i);
            KeyInfo keyInfoForListEntry = keyInfo.copy();
            keyInfoForListEntry.addElementToPath(i);
            Object partialList = getKeyValues(listEntry, componentSchema, keyNameElements, elementIndex + 1, keyInfoList, keyInfoForListEntry);
            if (partialList == null) {
                return null;
            }
        }
    } else if (property.getSchema() != null) {
        return getKeyValues(value, property.getSchema(), keyNameElements, elementIndex + 1, keyInfoList, keyInfo);
    } else {
        keyInfo.setValue(String.valueOf(value));
        keyInfoList.add(keyInfo);
    }
    return keyInfoList;
}
Also used : Schema(io.s4.schema.Schema) List(java.util.List) ArrayList(java.util.ArrayList) Property(io.s4.schema.Schema.Property)

Example 34 with Schema

use of org.h2.schema.Schema in project core by s4.

the class EventClock method update.

public void update(EventWrapper eventWrapper) {
    long eventTime = -1;
    String streamName = eventWrapper.getStreamName();
    String fieldName = eventClockStreamsMap.get(streamName);
    if (fieldName != null) {
        Object event = eventWrapper.getEvent();
        Schema schema = schemaContainer.getSchema(event.getClass());
        Property property = schema.getProperties().get(fieldName);
        if (property != null && (property.getType().equals(Long.TYPE) || property.getType().equals(Long.class))) {
            try {
                eventTime = (Long) property.getGetterMethod().invoke(event);
                updateTime(eventTime);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : Schema(io.s4.schema.Schema) Property(io.s4.schema.Schema.Property)

Example 35 with Schema

use of org.h2.schema.Schema in project ignite by apache.

the class IgniteH2Indexing method unregisterCache.

/** {@inheritDoc} */
@Override
public void unregisterCache(String cacheName) {
    String schemaName = schema(cacheName);
    boolean dflt = isDefaultSchema(schemaName);
    H2Schema schema = dflt ? schemas.get(schemaName) : schemas.remove(schemaName);
    if (schema != null) {
        mapQryExec.onCacheStop(cacheName);
        dmlProc.onCacheStop(cacheName);
        // Remove this mapping only after callback to DML proc - it needs that mapping internally
        cacheName2schema.remove(cacheName);
        // Drop tables.
        Collection<H2TableDescriptor> rmvTbls = new HashSet<>();
        for (H2TableDescriptor tbl : schema.tables()) {
            if (F.eq(tbl.cache().name(), cacheName)) {
                try {
                    dropTable(tbl);
                } catch (IgniteCheckedException e) {
                    U.error(log, "Failed to drop table on cache stop (will ignore): " + tbl.fullTableName(), e);
                }
                schema.drop(tbl);
                rmvTbls.add(tbl);
            }
        }
        if (!dflt) {
            try {
                dropSchema(schemaName);
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
            }
        }
        for (H2TableDescriptor tbl : rmvTbls) {
            for (Index idx : tbl.table().getIndexes()) idx.close(null);
        }
        int cacheId = CU.cacheId(cacheName);
        for (Iterator<Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery>> it = twoStepCache.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<H2TwoStepCachedQueryKey, H2TwoStepCachedQuery> e = it.next();
            GridCacheTwoStepQuery qry = e.getValue().query();
            if (!F.isEmpty(qry.cacheIds()) && qry.cacheIds().contains(cacheId))
                it.remove();
        }
    }
}
Also used : GridCacheTwoStepQuery(org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Aggregations

ResultSet (java.sql.ResultSet)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 PreparedStatement (java.sql.PreparedStatement)9 Statement (java.sql.Statement)9 ArrayList (java.util.ArrayList)9 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)9 SimpleResultSet (org.h2.tools.SimpleResultSet)9 List (java.util.List)8 Schema (io.s4.schema.Schema)7 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 Property (io.s4.schema.Schema.Property)6 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 IgniteException (org.apache.ignite.IgniteException)4 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)4 GridH2QueryContext (org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext)4 GridSqlStatement (org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement)4 Schema (org.h2.schema.Schema)4 TypeLiteral (com.google.inject.TypeLiteral)3