def to_bq(self, schema, not_null=False, boolean=False): lhs = BQLang[self.lhs].partial_eval() rhs = BQLang[self.rhs].partial_eval() lhs_sql = lhs.to_bq(schema, not_null=True) rhs_sql = rhs.to_bq(schema, not_null=True) if is_literal(rhs) and lhs_sql[0].sql.b != None and rhs.value in ("T", "F"): rhs_sql = BooleanOp(rhs).to_bq(schema) if is_literal(lhs) and rhs_sql[0].sql.b != None and lhs.value in ("T", "F"): lhs_sql = BooleanOp(lhs).to_bq(schema) if len(lhs_sql) != len(rhs_sql): Log.error("lhs and rhs have different dimensionality!?") acc = [] for l, r in zip(lhs_sql, rhs_sql): for t in "bsnj": if r.sql[t] == None: if l.sql[t] == None: pass else: acc.append(ConcatSQL(l.sql[t], SQL_IS_NULL)) elif l.sql[t] == None: acc.append(ConcatSQL(r.sql[t], SQL_IS_NULL)) else: acc.append( ConcatSQL(sql_iso(l.sql[t]), SQL_EQ, sql_iso(r.sql[t]))) if not acc: return FALSE.to_bq(schema) else: return wrap([{"name": ".", "sql": {"b": JoinSQL(SQL_OR, acc)}}])
def to_bq(self, schema, not_null=False, boolean=False): term = BQLang[self.term].partial_eval() if term.type == "boolean": sql = term.to_bq(schema) return sql elif is_literal(term) and term.value in ("T", "F"): if term.value == "T": return TRUE.to_bq(schema) else: return FALSE.to_bq(schema) else: sql = term.exists().partial_eval().to_bq(schema) return sql
def to_bq(self, schema, not_null=False, boolean=False): value = BQLang[self.expr].partial_eval() missing_value = value.missing().partial_eval() if not is_op(missing_value, MissingOp): return missing_value.to_bq(schema) value_sql = value.to_bq(schema) if value_sql.type == OBJECT: return FALSE.to_bq(schema) return BQLScript( data_type=BOOLEAN, expr=ConcatSQL(sql_iso(value_sql), SQL_IS_NULL), frum=self, miss=FALSE, many=False, schema=schema )
def to_bq(self, schema, not_null=False, boolean=False): lhs = BQLang[self.lhs].to_bq(schema) rhs = BQLang[self.rhs].to_bq(schema) acc = [] if len(lhs) != len(rhs): Log.error("lhs and rhs have different dimensionality!?") for l, r in zip(lhs, rhs): for t in "bsnj": if l.sql[t] == None: if r.sql[t] == None: pass else: acc.append(sql_iso(r.sql[t]) + SQL_IS_NULL) elif l.sql[t] is ZERO: if r.sql[t] == None: acc.append(SQL_FALSE) elif r.sql[t] is ZERO: Log.error( "Expecting expression to have been simplified already" ) else: acc.append(r.sql[t]) else: if r.sql[t] == None: acc.append(sql_iso(l.sql[t]) + SQL_IS_NULL) elif r.sql[t] is ZERO: acc.append(l.sql[t]) else: acc.append( sql_iso(l.sql[t]) + " = " + sql_iso(r.sql[t])) if not acc: return FALSE.to_bq(schema) else: return BQLScript( expr=SQL_OR.join(acc), frum=self, data_type=BOOLEAN, miss=FALSE, schema=schema, )