All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencypher.v9_0.expressions.CachedProperty.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) Neo4j Sweden AB (http://neo4j.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.opencypher.v9_0.expressions

import org.opencypher.v9_0.expressions.ASTCachedProperty.RuntimeKey
import org.opencypher.v9_0.util.InputPosition

sealed trait EntityType

case object NODE_TYPE extends EntityType

case object RELATIONSHIP_TYPE extends EntityType

/**
 * Common super class of [[CachedProperty]]
 * and its slotted specializations.
 */
trait ASTCachedProperty extends LogicalProperty {
  /**
   * @return the type of the entity for which a property is cached.
   */
  def entityType: EntityType

  /**
   * @return the original name of the entity for which a property is cached.
   */
  def originalEntityName: String

  /**
   * @return the name of the entity for which a property is cached.
   */
  def entityName: String

  /**
   * @return the property key name
   */
  def propertyKey: PropertyKeyName

  override val map: Expression = Variable(entityName)(this.position)

  /**
   * @return a textual representation of the entity and the property in the form `n.prop`
   */
  def propertyAccessString: String = s"$entityName.${propertyKey.name}"

  /**
   * @return the runtime key to be used when using this cached property in maps or sets at runtime,
   *         if different cached properties (different implementation or different current variable name)
   *         should be treated as if they were equal.
   */
  def runtimeKey: RuntimeKey = RuntimeKey(originalEntityName, propertyKey, entityType)(entityName)
}

object ASTCachedProperty {

  /**
   * Used to match equivalent cached properties at runtime.
   */
  case class RuntimeKey(originalEntityName: String,
                        propertyKey: PropertyKeyName,
                        entityType: EntityType)
                       (val entityName: String) {
    /**
     * @return a textual representation of the entity and the property in the form `n.prop`
     */
    def propertyAccessString: String = s"$entityName.${propertyKey.name}"

    def asCanonicalStringVal: String = s"cache[$propertyAccessString]"
  }
}

/**
 * A property value that is cached in the execution context. Such a value can be
 * retrieved very fast, but care has to be taken to it doesn't get out-dated by writes to
 * the graph/transaction state.
 *
 * @param originalEntityName the name of the variable how it appeared in the first Property access.
 * @param entityVariable     the variable how it appeared in this particular Property. It can have a different name than `originalEntityName`,
 *                           if the variable name was changed in between.
 * @param knownToAccessStore `true` if we know that the evaluation of this CachedProperty will access the store, `false` otherwise.
 *                           This is purely used for Cost estimation and has no effect on the runtime.
 */
case class CachedProperty(override val originalEntityName: String,
                          entityVariable: LogicalVariable,
                          override val propertyKey: PropertyKeyName,
                          override val entityType: EntityType,
                          knownToAccessStore: Boolean = false)(val position: InputPosition) extends ASTCachedProperty {

  override val entityName: String = entityVariable.name

  override def asCanonicalStringVal: String = s"cache[$propertyAccessString]"
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy