cube icon indicating copy to clipboard operation
cube copied to clipboard

Geo filters support

Open sourav-jha opened this issue 3 years ago • 9 comments

Problem

We want to write a custom SQL filter with 2 columns(lat ,long).

Example SQL

SELECT * FROM WHERE (point( -122.4194, 37.7749) <@> point(longitude, latitude)) < 15;

sourav-jha avatar Nov 22 '21 09:11 sourav-jha

@paveltiunov kindly reply

sourav-jha avatar Nov 24 '21 11:11 sourav-jha

Hey @sourav-jha ! It can be achieved by introducing dimension as following:

cube(`Cube`, {
  // ...
  dimensions: {
    distanceFromPoint: {
      sql: `(point( -122.4194, 37.7749) <@> point(${CUBE}.longitude, ${CUBE}.latitude))`,
      type: `number`
    }
  }
})

paveltiunov avatar Nov 25 '21 22:11 paveltiunov

@paveltiunov these values are (-122.4194, 37.7749) dynamic, it will change per query. SELECT * FROM WHERE (point( long_passed_by_user, lat_passed_by_user) <@> point(longitude, latitude)) < 15;

sourav-jha avatar Nov 26 '21 04:11 sourav-jha

@paveltiunov is this possible?

sourav-jha avatar Dec 01 '21 09:12 sourav-jha

@paveltiunov kindly reply

sourav-jha avatar Dec 02 '21 17:12 sourav-jha

@sourav-jha There's no straightforward way to use geo-filters as of now. Let's use this issue to track the status of this problem. The workaround is to have longitude and latitude dimensions and use gt lt filters and FILTER_PARAMS to extract information about the center as following:

cube(`Cube`, {
  sql: `select * from geo_points WHERE ${FILTER_PARAMS.Cube.longitude.filter((fromLongitude, toLongitude) => 
  FILTER_PARAMS.Cube.latitude.filter((fromLatitude, toLatitude) => `(point((${fromLongitude} + ${toLongitude}) / 2, (${fromLatitude} + ${toLatitude}) / 2) <@> point(longitude, latitude)) < 15`)
  )}`,

  dimensions: {
    longitude: {
      sql: `longitude`,
      type: `number`
    },

    latitude: {
      sql: `latitude`,
      type: `number`
    }
  }
});

paveltiunov avatar Dec 04 '21 05:12 paveltiunov

@paveltiunov is this below SQL possible: select c1, (c2 * user_input) AS c3 from t1 where c1 and c2 are columns of table t1 and use_input is some dynamic value provided by the user

sourav-jha avatar Dec 07 '21 12:12 sourav-jha

@paveltiunov Any news? I have the same use case

dker92 avatar Sep 01 '22 14:09 dker92

Any updates?

elhe26 avatar Jan 11 '24 13:01 elhe26