APACHE钙|使用RelNode在弹性搜索上执行插入操作?

时间:2019-05-17 11:23:13

标签: elasticsearch insert insert-update dml apache-calcite

我的报价分为两个部分: 1.我想使用方解石relnode在elasticsearch上执行DML操作(插入/更新/删除)。但是,由于与其他事物有关的某些或其他问题,包括对方解石的了解不足以及对其进行relnode / tablemodify预处理,我无法完成它。

  1. 我可以查询弹性搜索,但有些问题却无法使用relnode在其中添加任何过滤条件。

SchemaPlus postschema = con.getRootSchema().getSubSchema("twitter2");
        FrameworkConfig postConfig = Frameworks.newConfigBuilder()
                .defaultSchema(postschema)
                .build();
        RelBuilder postBuilder = RelBuilder.create(postConfig);
        String fields[] = {"_id", "name"};
        RelNode relSelect = postBuilder.scan("user").project(postBuilder.field("_MAP")).build();
        RelRunner runnerSelect = (RelRunner) con.unwrap(Class.forName("org.apache.calcite.tools.RelRunner"));
        ResultSet insRes = runnerSelect.prepare(relSelect).executeQuery();

我尝试创建ElasticsearchtableModify以及与JdbcTableModify相似的各个规则,但是我感到迷路并在丛林中跳动。

RelNode relInsert = LogicalTableModify.create(postBuilder.scan("user").build().getTable(), Prepare.CatalogReader.THREAD_LOCAL.get(), tryInsert, TableModify.Operation.INSERT, null, null, true);
RelRunner runnerInsert = (RelRunner) con.unwrap(Class.forName("org.apache.calcite.tools.RelRunner"));
        for (RelOptRule rule : ElasticsearchRules.RULES) {
            relInsert.getCluster().getPlanner().addRule(rule);
        }
runnerInsert.prepare(relInsert).executeQuery();

公共静态类ElasticsearchTableModificationRule扩展了ElasticsearchRules.ElasticsearchConverterRule {     私有静态最终ElasticsearchTableModificationRule INSTANCE = new ElasticsearchTableModificationRule();

/** Creates a JdbcTableModificationRule. */
private ElasticsearchTableModificationRule() {
  super(TableModify.class, Convention.NONE,  ElasticsearchRel.CONVENTION,  "ElasticSearchModificationRule");
}

@Override public RelNode convert(RelNode rel) {
  final TableModify modify =
          (TableModify) rel;
  final ModifiableTable modifiableTable =
          modify.getTable().unwrap(ModifiableTable.class);
  if (modifiableTable == null) {
    return null;
  }
  final RelTraitSet traitSet =
          modify.getTraitSet().replace(out);
  return new ElasticsearchRules.ElasticsearchTableModify(
          modify.getCluster(), traitSet,
          modify.getTable(),
          modify.getCatalogReader(),
          convert(modify.getInput(), traitSet),
          modify.getOperation(),
          modify.getUpdateColumnList(),
          modify.getSourceExpressionList(),
          modify.isFlattened());
}

}

公共静态类ElasticsearchTableModify扩展了TableModify实现的ElasticsearchRel {     私有最终表达式表达式;

public ElasticsearchTableModify(RelOptCluster cluster,
                                RelTraitSet traitSet,
                                RelOptTable table,
                                Prepare.CatalogReader catalogReader,
                                RelNode input,
                                Operation operation,
                                List<String> updateColumnList,
                                List<RexNode> sourceExpressionList,
                                boolean flattened) {
  super(cluster, traitSet, table, catalogReader, input, operation,
          updateColumnList, sourceExpressionList, flattened);
  assert input.getConvention() instanceof ElasticsearchConvention;
  assert getConvention() instanceof ElasticsearchConvention;
  final ModifiableTable modifiableTable =
          table.unwrap(ModifiableTable.class);
  if (modifiableTable == null) {
    throw new AssertionError(); // TODO: user error in validator
  }
  this.expression = table.getExpression(Queryable.class);
  if (expression == null) {
    throw new AssertionError(); // TODO: user error in validator
  }
}

@Override

公共无效工具(实施者实施者){

}

@Override
public RelOptCost computeSelfCost(RelOptPlanner planner,
                                  RelMetadataQuery mq) {
  return super.computeSelfCost(planner, mq).multiplyBy(.001);
}

@Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
  return new ElasticsearchRules.ElasticsearchTableModify(
          getCluster(), traitSet, getTable(), getCatalogReader(),
          sole(inputs), getOperation(), getUpdateColumnList(),
          getSourceExpressionList(), isFlattened());
}
/*public ElasticsearchImplementor.Result implement(ElasticsearchImplementor implementor) {
  return implementor.implement(this);
}*/

}

如果已经存在在弹性搜索上执行DML操作的支持,可以有人使用RelNode / TableModify(无Sql)为我提供相同的示例代码来完成它,以帮助我理解它。

还希望一些示例代码将过滤条件放入relnode并从elasticsearch获得结果。

0 个答案:

没有答案