Class Attribute
- All Implemented Interfaces:
NamedWriteable,Writeable,Resolvable
- Direct Known Subclasses:
EmptyAttribute,TypedAttribute,UnresolvedAttribute
Expressions that can be materialized and describe properties of the derived table.
In other words, an attribute represent a column in the results of a query.
In the statement SELECT ABS(foo), A, B+C FROM ... the three named
expressions ABS(foo), A, B+C get converted to attributes and the user can
only see Attributes.
In the statement SELECT foo FROM TABLE WHERE foo > 10 + 1 only foo inside the SELECT
is a named expression (an Alias will be created automatically for it).
The rest are not as they are not part of the projection and thus are not part of the derived table.
Note on equality: Because the name alone is not sufficient to identify an attribute
(two different relations can have the same attribute name), attributes get a unique NamedExpression.id()
assigned at creation which is respected in equality checks and hashing.
Caution! semanticEquals(Expression) and semanticHash() rely solely on the id.
But this doesn't extend to expressions containing attributes as children.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA wrapper class where equality of the contained attribute ignores theNamedExpression.id().Nested classes/interfaces inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
Expression.TypeResolutionNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringChanging this will break bwc with 8.15, seeFieldAttribute.fieldName().Fields inherited from class org.elasticsearch.xpack.esql.core.tree.Node
TO_STRING_MAX_WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionAttribute(Source source, String qualifier, String name, Nullability nullability, NameId id, boolean synthetic) Attribute(Source source, String name, Nullability nullability, NameId id) Attribute(Source source, String name, Nullability nullability, NameId id, boolean synthetic) -
Method Summary
Modifier and TypeMethodDescriptionprotected Expressionprotected voidcheckAndSerializeQualifier(PlanStreamOutput out, TransportVersion version) protected abstract Attributeclone(Source source, String qualifier, String name, DataType type, Nullability nullability, NameId id, boolean synthetic) static booleandataTypeEquals(List<Attribute> left, List<Attribute> right) Compares the size and datatypes of two lists of attributes for equality.ignoreId()protected booleaninnerEquals(Object o, boolean ignoreIds) The actual equality check, after shortcuttingthis == oand class checks.protected intinnerHashCode(boolean ignoreIds) abstract booleanabstract booleanisMetric()protected abstract Stringlabel()nullable()static StringrawTemporaryName(String... parts) protected static StringreadQualifier(PlanStreamInput in, TransportVersion version) final ExpressionreplaceChildren(List<Expression> newChildren) booleansemanticEquals(Expression other) Whether this expression means the same asother, even if they are not exactly equal.intA hash code that is consistent withExpression.semanticEquals(org.elasticsearch.xpack.esql.core.expression.Expression).toString()withDataType(DataType type) withLocation(Source source) withNullability(Nullability nullability) withQualifier(String qualifier) Methods inherited from class org.elasticsearch.xpack.esql.core.expression.NamedExpression
equals, equals, hashCode, hashCode, id, name, syntheticMethods inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
canonical, childrenResolved, dataType, fold, foldable, propertiesToString, resolved, resolveType, typeResolvedMethods inherited from class org.elasticsearch.xpack.esql.core.tree.Node
anyMatch, children, collect, collectFirstChildren, collectLeaves, doCollectFirst, forEachDown, forEachDown, forEachDownMayReturnEarly, forEachProperty, forEachPropertyDown, forEachPropertyOnly, forEachPropertyUp, forEachUp, forEachUp, info, nodeName, nodeProperties, replaceChildrenSameSize, source, sourceLocation, sourceText, transformChildren, transformDown, transformDown, transformDown, transformNodeProps, transformPropertiesDown, transformPropertiesOnly, transformPropertiesUp, transformUp, transformUp, transformUpMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.common.io.stream.NamedWriteable
getWriteableName
-
Field Details
-
SYNTHETIC_ATTRIBUTE_NAME_PREFIX
Changing this will break bwc with 8.15, seeFieldAttribute.fieldName().- See Also:
-
-
Constructor Details
-
Attribute
-
Attribute
-
Attribute
-
Attribute
public Attribute(Source source, @Nullable String qualifier, String name, Nullability nullability, @Nullable NameId id) -
Attribute
public Attribute(Source source, String name, Nullability nullability, @Nullable NameId id, boolean synthetic) -
Attribute
public Attribute(Source source, @Nullable String qualifier, String name, Nullability nullability, @Nullable NameId id, boolean synthetic)
-
-
Method Details
-
ignoreId
-
rawTemporaryName
-
replaceChildren
- Specified by:
replaceChildrenin classNode<Expression>
-
qualifier
-
qualifiedName
-
nullable
- Specified by:
nullablein classExpression
-
references
Description copied from class:Expression- Overrides:
referencesin classExpression
-
withLocation
-
withQualifier
-
withName
-
withNullability
-
withId
-
withDataType
-
clone
-
toAttribute
Description copied from class:NamedExpressionTry to return eitherthisif it is anAttribute, or aReferenceAttributeto it otherwise. Return anUnresolvedAttributeif this is unresolved.- Specified by:
toAttributein classNamedExpression
-
semanticHash
public int semanticHash()Description copied from class:ExpressionA hash code that is consistent withExpression.semanticEquals(org.elasticsearch.xpack.esql.core.expression.Expression).- Overrides:
semanticHashin classExpression
-
semanticEquals
Description copied from class:ExpressionWhether this expression means the same asother, even if they are not exactly equal. For example,a + bandb + aare not equal, but they are semantically equal.If two expressions are equal, they are also semantically equal, but the reverse is generally not true.
Caution!
semanticEquals(Expression)is especially lenient, as it considers two attributes with the sameNameIdto be semantically equal, even if they have different data types or are represented using different classes.But this doesn't extend to expressions containing attributes as children, which is pretty inconsistent. We have to revisit this before using
Expression.semanticEquals(org.elasticsearch.xpack.esql.core.expression.Expression)in more places.- Overrides:
semanticEqualsin classExpression
-
canonicalize
- Overrides:
canonicalizein classExpression
-
innerHashCode
protected int innerHashCode(boolean ignoreIds) - Overrides:
innerHashCodein classNamedExpression
-
innerEquals
Description copied from class:NamedExpressionThe actual equality check, after shortcuttingthis == oand class checks.- Overrides:
innerEqualsin classNamedExpression
-
toString
- Overrides:
toStringin classNamedExpression
-
nodeString
- Overrides:
nodeStringin classNamedExpression
-
label
-
dataTypeEquals
Compares the size and datatypes of two lists of attributes for equality. -
isDimension
public abstract boolean isDimension()- Returns:
- true if the attribute represents a TSDB dimension type
-
isMetric
public abstract boolean isMetric()- Returns:
- true if the attribute represents a TSDB metric type
-
checkAndSerializeQualifier
protected void checkAndSerializeQualifier(PlanStreamOutput out, TransportVersion version) throws IOException - Throws:
IOException
-
readQualifier
protected static String readQualifier(PlanStreamInput in, TransportVersion version) throws IOException - Throws:
IOException
-