OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.rel.rules.InjectFilterRule Class Reference
+ Inheritance diagram for org.apache.calcite.rel.rules.InjectFilterRule:
+ Collaboration diagram for org.apache.calcite.rel.rules.InjectFilterRule:

Classes

interface  Config
 

Public Member Functions

 InjectFilterRule (Config config, List< Restriction > restrictions)
 
void onMatch (RelOptRuleCall call)
 

Static Public Attributes

static Set< String > visitedMemo = new HashSet<>()
 

Package Functions

void clearMemo ()
 

Package Attributes

final List< Restrictionrestrictions
 

Static Package Attributes

static final Logger HEAVYDBLOGGER = LoggerFactory.getLogger(InjectFilterRule.class)
 

Detailed Description

Definition at line 38 of file InjectFilterRule.java.

Constructor & Destructor Documentation

org.apache.calcite.rel.rules.InjectFilterRule.InjectFilterRule ( Config  config,
List< Restriction restrictions 
)
inline

Definition at line 45 of file InjectFilterRule.java.

References org.apache.calcite.rel.rules.InjectFilterRule.clearMemo(), and org.apache.calcite.rel.rules.InjectFilterRule.restrictions.

Referenced by org.apache.calcite.rel.rules.InjectFilterRule.Config.toRule().

45  {
46  super(config);
47  this.restrictions = restrictions;
48  clearMemo();
49  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

void org.apache.calcite.rel.rules.InjectFilterRule.clearMemo ( )
inlinepackage

Definition at line 51 of file InjectFilterRule.java.

Referenced by org.apache.calcite.rel.rules.InjectFilterRule.InjectFilterRule().

51  {
52  visitedMemo.clear();
53  }

+ Here is the caller graph for this function:

void org.apache.calcite.rel.rules.InjectFilterRule.onMatch ( RelOptRuleCall  call)
inline

Definition at line 56 of file InjectFilterRule.java.

References field(), org.apache.calcite.rel.rules.InjectFilterRule.restrictions, and org.apache.calcite.rel.rules.InjectFilterRule.visitedMemo.

56  {
57  LogicalTableScan childScanNode = call.rel(0);
58  String scanNodeString = childScanNode.toString();
59  if (visitedMemo.contains(scanNodeString)) {
60  return;
61  } else {
62  visitedMemo.add(scanNodeString);
63  }
64  RelOptTable table = childScanNode.getTable();
65  List<String> qname = table.getQualifiedName();
66 
67  String query_database = null;
68  String query_table = null;
69  if (qname.size() == 2) {
70  query_database = qname.get(0);
71  query_table = qname.get(1);
72  }
73  if (query_database == null || query_database.isEmpty() || query_table == null
74  || query_table.isEmpty()) {
75  throw new RuntimeException(
76  "Restrictions: Expected qualified name as [database, table] but got: "
77  + qname);
78  }
79 
80  ArrayList<RexNode> orList = new ArrayList<RexNode>();
81  RelBuilder builder = call.builder();
82  RexBuilder rBuilder = builder.getRexBuilder();
83  builder = builder.push(childScanNode);
84  boolean found = false;
85  for (Restriction restriction : restrictions) {
86  // Match the database name.
87  String rest_database = restriction.getRestrictionDatabase();
88  if (rest_database != null && !rest_database.isEmpty()
89  && !rest_database.equals(query_database)) {
90  // TODO(sy): Maybe remove the isEmpty() wildcarding in HEAVY.AI 6.0.
91  HEAVYDBLOGGER.debug("RLS row-level security restriction for database "
92  + rest_database + " ignored because this query is on database "
93  + query_database);
94  continue;
95  }
96 
97  // Match the table name.
98  String rest_table = restriction.getRestrictionTable();
99  if (rest_table != null && !rest_table.isEmpty()
100  && !rest_table.equals(query_table)) {
101  // TODO(sy): Maybe remove the isEmpty() wildcarding in HEAVY.AI 6.0.
102  HEAVYDBLOGGER.debug("RLS row-level security restriction for table " + rest_table
103  + " ignored because this query is on table " + query_table);
104  continue;
105  }
106 
107  // Match the column name.
108  RelDataTypeField field = table.getRowType().getField(
109  restriction.getRestrictionColumn(), false, false);
110  if (field == null) {
111  HEAVYDBLOGGER.debug("RLS row-level security restriction for column "
112  + restriction.getRestrictionColumn()
113  + " ignored because column not present in query table " + query_table);
114  continue;
115  }
116 
117  // Generate the RLS row-level security filter for one Restriction.
118  found = true;
119  HEAVYDBLOGGER.debug(
120  "Scan is " + childScanNode.toString() + " TABLE is " + table.toString());
121  HEAVYDBLOGGER.debug("Column " + restriction.getRestrictionColumn()
122  + " exists in table " + table.getQualifiedName());
123 
124  for (String val : restriction.getRestrictionValues()) {
125  HEAVYDBLOGGER.debug("Column is " + restriction.getRestrictionColumn()
126  + " literal is '" + val + "'");
127  RexNode lit;
128  if (SqlTypeName.NUMERIC_TYPES.indexOf(field.getType().getSqlTypeName()) == -1) {
129  if (val.length() < 2 || val.charAt(0) != '\''
130  || val.charAt(val.length() - 1) != '\'') {
131  throw new RuntimeException(
132  "Restrictions: Expected a CREATE POLICY VALUES string with single quotes.");
133  }
134  lit = rBuilder.makeLiteral(
135  val.substring(1, val.length() - 1), field.getType(), false);
136  } else {
137  lit = rBuilder.makeLiteral(Integer.parseInt(val), field.getType(), false);
138  }
139  RexNode rn = builder.call(SqlStdOperatorTable.EQUALS,
140  builder.field(restriction.getRestrictionColumn()),
141  lit);
142  orList.add(rn);
143  }
144  }
145 
146  if (found) {
147  RexNode relOr = builder.call(SqlStdOperatorTable.OR, orList);
148  final RelNode newNode = builder.filter(relOr).build();
149  call.transformTo(newNode);
150  }
151  };
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33

+ Here is the call graph for this function:

Member Data Documentation

final Logger org.apache.calcite.rel.rules.InjectFilterRule.HEAVYDBLOGGER = LoggerFactory.getLogger(InjectFilterRule.class)
staticpackage

Definition at line 42 of file InjectFilterRule.java.

final List<Restriction> org.apache.calcite.rel.rules.InjectFilterRule.restrictions
package
Set<String> org.apache.calcite.rel.rules.InjectFilterRule.visitedMemo = new HashSet<>()
static

The documentation for this class was generated from the following file: