<commit_before>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2016, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.geopkg;

import java.io.IOException;
import java.io.Writer;
import java.sql.Time;
import java.sql.Timestamp;
import org.geotools.data.jdbc.FilterToSQLException;
import org.geotools.filter.FilterCapabilities;
import org.geotools.jdbc.PreparedFilterToSQL;
import org.geotools.jdbc.PrimaryKeyColumn;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.spatial.BBOX;
import org.opengis.filter.spatial.BinarySpatialOperator;

/** @author ian */
public class GeoPkgFilterToSQL extends PreparedFilterToSQL {

    GeoPkgDialect dialect;

    /** @param dialect */
    public GeoPkgFilterToSQL(GeoPkgDialect dialect) {
        super(dialect);
        this.dialect = dialect;
    }

    /**
     * Override done to ensure we don't complain if there is a BBOX filter, even if we claim not to
     * support it
     */
    public void encode(Filter filter) throws FilterToSQLException {
        if (out == null) throw new FilterToSQLException("Can't encode to a null writer.");
        // hack, we lied about being able to support BBOX, because the implementation is
        // just partial, so here don't complain if we got one, it means the dialect already
        // set the filter correctly
        FilterCapabilities caps = createFilterCapabilities();
        caps.addType(BBOX.class);
        if (caps.fullySupports(filter)) {

            try {
                if (!inline) {
                    out.write("WHERE ");
                }

                filter.accept(this, null);
            } catch (java.io.IOException ioe) {
                LOGGER.warning("Unable to export filter" + ioe);
                throw new FilterToSQLException("Problem writing filter: ", ioe);
            }
        } else {
            throw new FilterToSQLException("Filter type not supported");
        }
    }

    /** @param out */
    public GeoPkgFilterToSQL(Writer out) {
        super(out);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Object visit(Literal expression, Object context) throws RuntimeException {
        if (!isPrepareEnabled()) return super.visit(expression, context);

        // evaluate the literal and store it for later
        Object literalValue =
                evaluateLiteral(expression, (context instanceof Class ? (Class) context : null));
        literalValues.add(literalValue);
        SRIDs.add(currentSRID);
        dimensions.add(currentDimension);

        Class clazz = null;
        if (context instanceof Class) clazz = (Class) context;
        else if (literalValue != null) clazz = literalValue.getClass();
        literalTypes.add(clazz);

        try {
            if (literalValue == null || dialect == null) {
                out.write("?");
            } else {<commit_msg>Add AttributeDescriptor to descriptors list to fix filtering of geopackages<commit_after>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2016, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.geopkg;

import java.io.IOException;
import java.io.Writer;
import java.sql.Time;
import java.sql.Timestamp;
import org.geotools.data.jdbc.FilterToSQLException;
import org.geotools.filter.FilterCapabilities;
import org.geotools.jdbc.PreparedFilterToSQL;
import org.geotools.jdbc.PrimaryKeyColumn;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.spatial.BBOX;
import org.opengis.filter.spatial.BinarySpatialOperator;

/** @author ian */
public class GeoPkgFilterToSQL extends PreparedFilterToSQL {

    GeoPkgDialect dialect;

    /** @param dialect */
    public GeoPkgFilterToSQL(GeoPkgDialect dialect) {
        super(dialect);
        this.dialect = dialect;
    }

    /**
     * Override done to ensure we don't complain if there is a BBOX filter, even if we claim not to
     * support it
     */
    public void encode(Filter filter) throws FilterToSQLException {
        if (out == null) throw new FilterToSQLException("Can't encode to a null writer.");
        // hack, we lied about being able to support BBOX, because the implementation is
        // just partial, so here don't complain if we got one, it means the dialect already
        // set the filter correctly
        FilterCapabilities caps = createFilterCapabilities();
        caps.addType(BBOX.class);
        if (caps.fullySupports(filter)) {

            try {
                if (!inline) {
                    out.write("WHERE ");
                }

                filter.accept(this, null);
            } catch (java.io.IOException ioe) {
                LOGGER.warning("Unable to export filter" + ioe);
                throw new FilterToSQLException("Problem writing filter: ", ioe);
            }
        } else {
            throw new FilterToSQLException("Filter type not supported");
        }
    }

    /** @param out */
    public GeoPkgFilterToSQL(Writer out) {
        super(out);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Object visit(Literal expression, Object context) throws RuntimeException {
        if (!isPrepareEnabled()) return super.visit(expression, context);

        // evaluate the literal and store it for later
        Object literalValue =
                evaluateLiteral(expression, (context instanceof Class ? (Class) context : null));
        literalValues.add(literalValue);
        SRIDs.add(currentSRID);
        dimensions.add(currentDimension);
        descriptors.add(context instanceof AttributeDescriptor ? (AttributeDescriptor)context : null);

        Class clazz = null;
        if (context instanceof Class) clazz = (Class) context;
        else if (literalValue != null) clazz = literalValue.getClass();
        literalTypes.add(clazz);

        try {
            if (literalValue == null || dialect == null) {
                out.write("?");
            } else {
{'fraction_non_alphanumeric': 0.08846719230255246, 'fraction_numerical': 0.0016036349057864494, 'mean_word_length': 2.690335305719921, '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': '5631583', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1990, 'n_words': 638}