private TupleSource processSystemQuery(CommandContext context, Command command,
DQPWorkContext workContext) throws TeiidComponentException, TeiidProcessingException {
String vdbName = workContext.getVdbName();
int vdbVersion = workContext.getVdbVersion();
VDBMetaData vdb = workContext.getVDB();
CompositeMetadataStore metadata = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
TransformationMetadata indexMetadata = vdb.getAttachment(TransformationMetadata.class);
Collection rows = new ArrayList();
int oid = 1;
if (command instanceof Query) {
Query query = (Query)command;
UnaryFromClause ufc = (UnaryFromClause)query.getFrom().getClauses().get(0);
GroupSymbol group = ufc.getGroup();
if (StringUtil.startsWithIgnoreCase(group.getNonCorrelationName(), CoreConstants.SYSTEM_ADMIN_MODEL)) {
final SystemAdminTables sysTable = SystemAdminTables.valueOf(group.getNonCorrelationName().substring(CoreConstants.SYSTEM_ADMIN_MODEL.length() + 1).toUpperCase());
switch (sysTable) {
case MATVIEWS:
for (Schema schema : getVisibleSchemas(vdb, metadata)) {
for (Table table : schema.getTables().values()) {
if (!table.isMaterialized()) {
continue;
}
String targetSchema = null;
String matTableName = null;
String state = null;
Timestamp updated = null;
Integer cardinaltity = null;
Boolean valid = null;
if (table.getMaterializedTable() == null) {
TempTableStore globalStore = context.getGlobalTableStore();
matTableName = RelationalPlanner.MAT_PREFIX+table.getFullName().toUpperCase();
MatTableInfo info = globalStore.getMatTableInfo(matTableName);
valid = info.isValid();
state = info.getState().name();
updated = info.getUpdateTime()==-1?null:new Timestamp(info.getUpdateTime());
TempMetadataID id = globalStore.getMetadataStore().getTempGroupID(matTableName);
if (id != null) {
cardinaltity = id.getCardinality();
}
//ttl, pref_mem - not part of proper metadata
} else {
Table t = table.getMaterializedTable();
matTableName = t.getName();
targetSchema = t.getParent().getName();
}
rows.add(Arrays.asList(vdbName, schema.getName(), table.getName(), targetSchema, matTableName, valid, state, updated, cardinaltity));
}
}
break;
case VDBRESOURCES:
String[] filePaths = indexMetadata.getVDBResourcePaths();
for (String filePath : filePaths) {
rows.add(Arrays.asList(filePath, new BlobType(indexMetadata.getVDBResourceAsBlob(filePath))));
}
break;
}
return new CollectionTupleSource(rows.iterator());
}
final SystemTables sysTable = SystemTables.valueOf(group.getNonCorrelationName().substring(CoreConstants.SYSTEM_MODEL.length() + 1).toUpperCase());
switch (sysTable) {
case DATATYPES:
for (Datatype datatype : metadata.getDatatypes()) {
rows.add(Arrays.asList(datatype.getName(), datatype.isBuiltin(), datatype.isBuiltin(), datatype.getName(), datatype.getJavaClassName(), datatype.getScale(),
datatype.getLength(), datatype.getNullType().toString(), datatype.isSigned(), datatype.isAutoIncrement(), datatype.isCaseSensitive(), datatype.getPrecisionLength(),
datatype.getRadix(), datatype.getSearchType().toString(), datatype.getUUID(), datatype.getRuntimeTypeName(), datatype.getBasetypeName(), datatype.getAnnotation(), oid++));
}
break;