// find source table (TODO: do this in analyzer)
QueryBody queryBody = analysis.getQuery().getQueryBody();
checkState(queryBody instanceof QuerySpecification, "Query is not a simple select statement");
List<Relation> relations = ((QuerySpecification) queryBody).getFrom();
checkState(relations.size() == 1, "Query has more than one source table");
Relation relation = Iterables.getOnlyElement(relations);
checkState(relation instanceof Table, "FROM clause is not a simple table name");
QualifiedTableName sourceTable = MetadataUtil.createQualifiedTableName(session, ((Table) relation).getName());
// create source table and optional import information
storageManager.insertTableSource(((NativeTableHandle) targetTable), sourceTable);