private Configuration conf = WaspConfiguration.create();
@Test
public void testCheckAndGetIndex() throws ZooKeeperConnectionException,
MetaException {
FTable table = FMetaTestUtil.getTestTable();
List<String> fields = new ArrayList<String>();
fields.add("c4");
fields.add("c5");
Index i1 = FMetaTestUtil.makeIndex(table, "i1", fields);
table.addIndex(i1);
fields = new ArrayList<String>();
fields.add("c5");
fields.add("c4");
Index i2 = FMetaTestUtil.makeIndex(table, "i2", fields);
table.addIndex(i2);
String sql1 = "SELECT c1, c2, c3 from test where c4=1 and c5=2;";
String sql2 = "SELECT c1, c2, c3 from test where c5=2 and c4=1;";
String[] sqlList = { sql1, sql2 }; // sql1, sql2, sql3
Index[] indexs = { i1, i2 }; // sql1, sql2, sql3
DruidDQLParser druidParser = new DruidDQLParser(conf);
for (int i = 0; i < sqlList.length; i++) {
String sql = sqlList[i];
context.setSql(sql);
try {
druidParser.parseSqlToStatement(context);
SQLStatement stmt = context.getStmt();
if (stmt instanceof SQLSelectStatement) {
MemFMetaStore fmetaServices = new MemFMetaStore();
TableSchemaCacheReader reader = TableSchemaCacheReader.getInstance(
conf, fmetaServices);
reader.addSchema(table.getTableName(), table);
MetaEventOperation metaEventOperation = new FMetaEventOperation(
reader);
SQLSelectStatement sqlSelectStatement = (SQLSelectStatement) stmt;
// this is SELECT clause