Skip to content

Instantly share code, notes, and snippets.

View masayuki038's full-sized avatar

Masayuki Takahashi masayuki038

View GitHub Profile
import sqlparse
import sys
import re
parsed = sqlparse.parse(sys.argv[1])
print(parsed[0])
for t in parsed[0].tokens:
print(type(t), t.ttype, t)
; ModuleID = '/var/lib/postgresql/12/main/1985.21.bc'
source_filename = "pg"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
%struct.ExprState = type { %struct.Node, i8, i8, i64, %struct.TupleTableSlot*, %struct.ExprEvalStep*, i64 (%struct.ExprState*, %struct.ExprContext*, i8*)*, %struct.Expr*, i8*, i32, i32, %struct.PlanState*, %struct.ParamListInfoData*, i64*, i8*, i64*, i8* }
%struct.Node = type { i32 }
%struct.TupleTableSlot = type { i32, i16, i16, %struct.TupleTableSlotOps*, %struct.TupleDescData*, i64*, i8*, %struct.MemoryContextData*, %struct.ItemPointerData, i32 }
%struct.TupleTableSlotOps = type { i64, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*)*, {}*, i64 (%struct.TupleTableSlot*, i32, i8*)*, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*, %struct.TupleTableSlot*)*, %struct.HeapTupleData* (%struct.TupleTableSlot*)*, %struct.MinimalTupleData* (%struct.TupleTableSlot*)*, %struct.Heap
; ModuleID = '/var/lib/postgresql/12/main/3410.0.bc'
source_filename = "pg"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
%struct.ExprState = type { %struct.Node, i8, i8, i64, %struct.TupleTableSlot*, %struct.ExprEvalStep*, i64 (%struct.ExprState*, %struct.ExprContext*, i8*)*, %struct.Expr*, i8*, i32, i32, %struct.PlanState*, %struct.ParamListInfoData*, i64*, i8*, i64*, i8* }
%struct.Node = type { i32 }
%struct.TupleTableSlot = type { i32, i16, i16, %struct.TupleTableSlotOps*, %struct.TupleDescData*, i64*, i8*, %struct.MemoryContextData*, %struct.ItemPointerData, i32 }
%struct.TupleTableSlotOps = type { i64, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*)*, {}*, i64 (%struct.TupleTableSlot*, i32, i8*)*, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*, %struct.TupleTableSlot*)*, %struct.HeapTupleData* (%struct.TupleTableSlot*)*, %struct.MinimalTupleData* (%struct.TupleTableSlot*)*, %struct.HeapT
/* Provide Declarations */
#include <stdarg.h>
#include <setjmp.h>
#include <limits.h>
#include <stdint.h>
#include <math.h>
#ifndef __cplusplus
typedef unsigned char bool;
#endif
; ModuleID = '/var/lib/postgresql/12/main/2832.0.bc'
source_filename = "pg"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
%struct.ExprState = type { %struct.Node, i8, i8, i64, %struct.TupleTableSlot*, %struct.ExprEvalStep*, i64 (%struct.ExprState*, %struct.ExprContext*, i8*)*, %struct.Expr*, i8*, i32, i32, %struct.PlanState*, %struct.ParamListInfoData*, i64*, i8*, i64*, i8* }
%struct.Node = type { i32 }
%struct.TupleTableSlot = type { i32, i16, i16, %struct.TupleTableSlotOps*, %struct.TupleDescData*, i64*, i8*, %struct.MemoryContextData*, %struct.ItemPointerData, i32 }
%struct.TupleTableSlotOps = type { i64, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*)*, {}*, i64 (%struct.TupleTableSlot*, i32, i8*)*, void (%struct.TupleTableSlot*)*, void (%struct.TupleTableSlot*, %struct.TupleTableSlot*)*, %struct.HeapTupleData* (%struct.TupleTableSlot*)*, %struct.MinimalTupleData* (%struct.TupleTableSlot*)*, %struct.HeapT
public class JdbcTest {
private final static String CONNECTION_URL = "jdbc:calcite:model=target/test-classes/model.json";
@BeforeClass
public static void setUpOnce() throws ClassNotFoundException {
Class.forName("org.apache.calcite.jdbc.Driver");
}
@Test
@Override
public void onMatch(RelOptRuleCall call) {
LogicalProject project = call.rel(0);
AvroTableScan scan = call.rel(1);
Integer[] fields = getProjectFields(project.getProjects());
call.transformTo(
new AvroTableScan(scan.getCluster(), scan.getTable(), fields)
);
}
public class AvroProjectTableScanRule extends RelOptRule {
static final AvroProjectTableScanRule INSTANCE = new AvroProjectTableScanRule();
public AvroProjectTableScanRule() {
super(RelOptRule.operand(
LogicalProject.class,
RelOptRule.operand(AvroTableScan.class, RelOptRule.none())
), "AvroProjectTableScanRule");
}
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());
return implementor.result(physType, Blocks.toBlock(
Expressions.call(
this.table.getExpression(AvroTable.class),
"project",
implementor.getRootExpression(),
Expressions.constant(this.fields)
)
@Override
public void register(RelOptPlanner planner) {
planner.addRule(AvroProjectTableScanRule.INSTANCE);
}