<commit_before>'use strict';

var dot = require('dot');
dot.templateSettings.strip = false;

var Node = require('../node');

var TYPE = 'intersection';
var PARAMS = {
    source: Node.PARAM.NODE(Node.GEOMETRY.ANY),
    target: Node.PARAM.NODE(Node.GEOMETRY.ANY)
};

var Intersection = Node.create(TYPE, PARAMS);

module.exports = Intersection;
module.exports.TYPE = TYPE;
module.exports.PARAMS = PARAMS;


Intersection.prototype.sql = function() {
    return query({
        sourceQuery: this.source.getQuery(),
        targetQuery: this.target.getQuery(),
        columnNames: this.source.getColumns()
    });
};

var queryTemplate = dot.template([
    'WITH',
    '_cdb_analysis_source AS (',
    ' {{=it.sourceQuery}}',
    '),',
    '_cdb_analysis_target AS (',
    ' {{=it.targetQuery}}',
    ')',
    'SELECT {{=it.sourceQueryColumns}}',
    'FROM _cdb_analysis_source JOIN _cdb_analysis_target',
    'ON ST_Intersects(_cdb_analysis_target.the_geom, _cdb_analysis_source.the_geom)'
].join('\n'));

function query(it) {
    it.sourceQueryColumns = it.columnNames.map(function(name) { return '_cdb_analysis_source.' + name; }).join(', ');
    return queryTemplate(it);
}<commit_msg>Do not use cte for intersections<commit_after>'use strict';

var dot = require('dot');
dot.templateSettings.strip = false;

var Node = require('../node');

var TYPE = 'intersection';
var PARAMS = {
    source: Node.PARAM.NODE(Node.GEOMETRY.ANY),
    target: Node.PARAM.NODE(Node.GEOMETRY.ANY)
};

var Intersection = Node.create(TYPE, PARAMS);

module.exports = Intersection;
module.exports.TYPE = TYPE;
module.exports.PARAMS = PARAMS;


Intersection.prototype.sql = function() {
    return queryTemplate({
        sourceQuery: this.source.getQuery(),
        targetQuery: this.target.getQuery()
    });
};

var queryTemplate = dot.template([
    'SELECT _cdb_analysis_source.*',
    'FROM ({{=it.sourceQuery}}) _cdb_analysis_source, ({{=it.targetQuery}}) _cdb_analysis_target',
    'WHERE ST_Intersects(_cdb_analysis_target.the_geom, _cdb_analysis_source.the_geom)'
].join('\n'));
{'fraction_non_alphanumeric': 0.15876089060987417, 'fraction_numerical': 0.0, 'mean_word_length': 4.3, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285237', 'n_tokens_mistral': 701, 'n_tokens_neox': 687, 'n_words': 125}