Class OSQLFunctionAbstract

java.lang.Object
com.orientechnologies.orient.core.sql.functions.OSQLFunctionAbstract
All Implemented Interfaces:
OSQLFunction
Direct Known Subclasses:
OLuceneCrossClassSearchFunction, OLuceneSearchFunctionTemplate, OLuceneSearchMoreLikeThisFunction, OSpatialFunctionAbstract, OSQLEnterpriseFunction, OSQLFunctionCoalesce, OSQLFunctionConfigurableAbstract, OSQLFunctionDate, OSQLFunctionDecode, OSQLFunctionDistance, OSQLFunctionDistinct, OSQLFunctionEncode, OSQLFunctionFormat, OSQLFunctionFormat, OSQLFunctionIf, OSQLFunctionIfNull, OSQLFunctionIndexKeySize, OSQLFunctionMode, OSQLFunctionPercentile, OSQLFunctionStrcmpci, OSQLFunctionSysdate, OSQLFunctionThrowCME, OSQLFunctionUUID, OSQLFunctionVariance, OSQLStaticReflectiveFunction, OSTAsBinaryFunction, OSTAsGeoJSONFunction, OSTAsTextFunction, OSTBufferFunction, OSTDisjointFunction, OSTEnvelopFunction, OSTEqualsFunction, OSTGeomFromGeoJSONFunction, OSTGeomFromTextFunction, OSTSrid

public abstract class OSQLFunctionAbstract extends Object implements OSQLFunction
Abstract class to extend to build Custom SQL Functions. Extend it and register it with: OSQLParser.getInstance().registerStatelessFunction() or OSQLParser.getInstance().registerStatefullFunction() to being used by the SQL engine.
Author:
Luca Garulli (l.garulli--(at)--orientdb.com)
  • Field Details

    • name

      protected String name
    • minParams

      protected int minParams
    • maxParams

      protected int maxParams
  • Constructor Details

    • OSQLFunctionAbstract

      public OSQLFunctionAbstract(String iName, int iMinParams, int iMaxParams)
  • Method Details

    • getName

      public String getName()
      Description copied from interface: OSQLFunction
      Function name, the name is used by the sql parser to identify a call this function.
      Specified by:
      getName in interface OSQLFunction
      Returns:
      String , function name, never null or empty.
    • getMinParams

      public int getMinParams()
      Description copied from interface: OSQLFunction
      Minimum number of parameter this function must have.
      Specified by:
      getMinParams in interface OSQLFunction
      Returns:
      minimum number of parameters
    • getMaxParams

      public int getMaxParams()
      Description copied from interface: OSQLFunction
      Maximum number of parameter this function can handle.
      Specified by:
      getMaxParams in interface OSQLFunction
      Returns:
      maximum number of parameters ??? -1 , negative or Integer.MAX_VALUE for unlimited ???
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • config

      public void config(Object[] iConfiguredParameters)
      Description copied from interface: OSQLFunction
      Configure the function.
      Specified by:
      config in interface OSQLFunction
    • aggregateResults

      public boolean aggregateResults()
      Description copied from interface: OSQLFunction
      A function can make calculation on several records before returning a result.

      Example of such function : sum, count, max, min ...

      The final result of the aggregation is obtain by calling OSQLFunction.getResult(OCommandContext)

      Specified by:
      aggregateResults in interface OSQLFunction
      Returns:
      true if function aggregate results
    • filterResult

      public boolean filterResult()
      Description copied from interface: OSQLFunction
      A function can act both as transformation or filtering records. If the function may reduce the number final records than it must return true.

      Function should return null for the execute method if the record must be excluded.

      Specified by:
      filterResult in interface OSQLFunction
      Returns:
      true if the function acts as a record filter.
    • getResult

      public Object getResult(OCommandContext ctx)
      Description copied from interface: OSQLFunction
      Only called when function aggregates results after all records have been passed to the function.
      Specified by:
      getResult in interface OSQLFunction
      Parameters:
      ctx - TODO
      Returns:
      Aggregation result
    • setResult

      public void setResult(Object iResult)
      Description copied from interface: OSQLFunction
      Called by OCommandExecutor, given parameter is the number of results. ??? strange ???
      Specified by:
      setResult in interface OSQLFunction
    • shouldMergeDistributedResult

      public boolean shouldMergeDistributedResult()
      Description copied from interface: OSQLFunction
      This method correspond to distributed query execution
      Specified by:
      shouldMergeDistributedResult in interface OSQLFunction
      Returns:
      true if results that comes from different nodes need to be merged to obtain valid one, false otherwise
    • mergeDistributedResult

      public Object mergeDistributedResult(List<Object> resultsToMerge)
      Description copied from interface: OSQLFunction
      This method correspond to distributed query execution
      Specified by:
      mergeDistributedResult in interface OSQLFunction
      Parameters:
      resultsToMerge - is the results that comes from different nodes
      Returns:
      is the valid merged result
    • returnDistributedResult

      protected boolean returnDistributedResult()
    • getDistributedStorageId

      protected String getDistributedStorageId(OCommandContext ctx)
    • getSingleItem

      protected Object getSingleItem(Object source)
      Attempt to extract a single item from object if it's a multi value OMultiValue If source is a multi value
      Parameters:
      source - a value to attempt extract single value from it
      Returns:
      If source is not a multi value, it will return source as is. If it is, it will return the single element in it. If source is a multi value with more than 1 element null is returned, indicating an error
    • getSingleProperty

      protected Object getSingleProperty(Object source, boolean requireSingleProperty)
      Attempts to identify the source as a map-like object with single property and return it.
      Parameters:
      source - The object to check
      requireSingleProperty - True if the method should return null when source doesn't have a single property. Otherwise, the object will be returned.
      Returns:
      If source is a map-like object with single property, that property will be returned If source is a map-like object with multiple properties and requireSingleProperty is true, null is returned indicating an error If source is not a map-like object, it is returned
    • getDatabase

      protected ODatabaseSession getDatabase(OCommandContext ctx)