ODPS-0130252
This topic describes the possible causes of the error code ODPS-0130252: Cartesian product is not allowed and provides solutions.
Error: cartesian product is not allowed without mapjoin
Error message example
ODPS-0130252:[m,n] Cartesian product is not allowed - cartesian product is not allowed without mapjoin
Cause
When two tables are joined without a join condition, a Cartesian product is produced. If odps.sql.allow.cartesian is set to false, the preceding error is reported.
Solution
The primary solution is to add a join condition to your query. Depending on the join type and table sizes, consider the following approaches:
When one of the tables in the
JOINis a small table, you can either add a join condition or setodps.sql.allow.cartesiantotrue.If both tables are large, you must add a join condition. Setting
odps.sql.allow.cartesiantotrueis strongly discouraged because it can cause data bloat.
Query examples
-- Fails: Cartesian products are not allowed with the current setting.
odps> SET odps.sql.allow.cartesian=false;
odps> SELECT t1. *
FROM src t1
JOIN src t2;
FAILED: ODPS-0130252:[3,1] Cartesian product is not allowed - cartesian product is not allowed without mapjoin
-- Correct: Add an ON clause for an equi-join.
odps> SELECT t1. *
FROM src t1
JOIN src t2
ON t1.key = t2.key;
-- Correct: For non-equi joins, specify the small table in a MAPJOIN hint.
odps> SELECT /*+mapjoin(t1) * / t1.*
FROM src t1
JOIN src t2
ON t1.key > t2.key;