-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/apache/master' into ignite…
…-18312-4
- Loading branch information
Showing
87 changed files
with
2,997 additions
and
1,155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
using Apache.Ignite.Core; | ||
using Apache.Ignite.Core.Compute; | ||
using Apache.Ignite.Core.Resource; | ||
|
||
namespace dotnet_helloworld | ||
{ | ||
public class JobScheduling | ||
{ | ||
public void Priority() | ||
{ | ||
// tag::priority[] | ||
// PriorityQueueCollisionSpi must be configured in the Spring XML configuration file ignite-helloworld.xml | ||
var cfg = new IgniteConfiguration | ||
{ | ||
SpringConfigUrl = "ignite-helloworld.xml" | ||
}; | ||
|
||
// Start a node. | ||
using var ignite = Ignition.Start(cfg); | ||
// end::priority[] | ||
} | ||
|
||
// tag::task-priority[] | ||
// Compute tasks must be annotated with the ComputeTaskSessionFullSupport attribute to support distributing | ||
// the task's session attributes to compute jobs that the task creates. | ||
[ComputeTaskSessionFullSupport] | ||
public class MyUrgentTask : ComputeTaskSplitAdapter<int, bool, bool> | ||
{ | ||
// Auto-injected task session. | ||
[TaskSessionResource] private IComputeTaskSession _taskSes; | ||
|
||
/// <inheritdoc /> | ||
protected override ICollection<IComputeJob<bool>> Split(int gridSize, int arg) | ||
{ | ||
// Set high task priority. | ||
_taskSes.SetAttribute("grid.task.priority", 10); | ||
|
||
var jobs = new List<IComputeJob<bool>>(gridSize); | ||
|
||
for (var i = 1; i <= gridSize; i++) | ||
{ | ||
jobs.Add(new MyUrgentJob()); | ||
} | ||
|
||
// These jobs will be executed with higher priority. | ||
return jobs; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Reduce(IList<IComputeJobResult<bool>> results) => results.All(r => r.Data); | ||
} | ||
// end::task-priority[] | ||
|
||
private class MyUrgentJob : ComputeJobAdapter<bool> | ||
{ | ||
public override bool Execute() => true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
.../java/org/apache/ignite/internal/processors/query/calcite/exec/exp/IgniteExpressions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.ignite.internal.processors.query.calcite.exec.exp; | ||
|
||
import java.lang.reflect.Type; | ||
import java.math.BigDecimal; | ||
import org.apache.calcite.linq4j.tree.Expression; | ||
import org.apache.calcite.linq4j.tree.ExpressionType; | ||
import org.apache.calcite.linq4j.tree.Expressions; | ||
import org.apache.calcite.linq4j.tree.Primitive; | ||
import org.apache.calcite.runtime.SqlFunctions; | ||
import org.apache.ignite.internal.processors.query.calcite.util.IgniteMath; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** Calcite liq4j expressions customized for Ignite. */ | ||
public class IgniteExpressions { | ||
/** Make binary expression with arithmetic operations override. */ | ||
public static Expression makeBinary(ExpressionType binaryType, Expression left, Expression right) { | ||
switch (binaryType) { | ||
case Add: | ||
return addExact(left, right); | ||
case Subtract: | ||
return subtractExact(left, right); | ||
case Multiply: | ||
return multiplyExact(left, right); | ||
case Divide: | ||
return divideExact(left, right); | ||
default: | ||
return Expressions.makeBinary(binaryType, left, right); | ||
} | ||
} | ||
|
||
/** Make unary expression with arithmetic operations override. */ | ||
public static Expression makeUnary(ExpressionType unaryType, Expression operand) { | ||
switch (unaryType) { | ||
case Negate: | ||
case NegateChecked: | ||
return negateExact(unaryType, operand); | ||
default: | ||
return Expressions.makeUnary(unaryType, operand); | ||
} | ||
} | ||
|
||
/** Generate expression for method IgniteMath.addExact() for integer subtypes. */ | ||
public static Expression addExact(Expression left, Expression right) { | ||
if (larger(left.getType(), right.getType()).isFixedNumeric()) | ||
return Expressions.call(IgniteMath.class, "addExact", left, right); | ||
|
||
return Expressions.makeBinary(ExpressionType.Add, left, right); | ||
} | ||
|
||
/** Generate expression for method IgniteMath.subtractExact() for integer subtypes. */ | ||
public static Expression subtractExact(Expression left, Expression right) { | ||
if (larger(left.getType(), right.getType()).isFixedNumeric()) | ||
return Expressions.call(IgniteMath.class, "subtractExact", left, right); | ||
|
||
return Expressions.makeBinary(ExpressionType.Subtract, left, right); | ||
} | ||
|
||
/** Generate expression for method IgniteMath.multiplyExact() for integer subtypes. */ | ||
public static Expression multiplyExact(Expression left, Expression right) { | ||
if (larger(left.getType(), right.getType()).isFixedNumeric()) | ||
return Expressions.call(IgniteMath.class, "multiplyExact", left, right); | ||
|
||
return Expressions.makeBinary(ExpressionType.Multiply, left, right); | ||
} | ||
|
||
/** Generate expression for method IgniteMath.divideExact() for integer subtypes. */ | ||
public static Expression divideExact(Expression left, Expression right) { | ||
if (larger(left.getType(), right.getType()).isFixedNumeric()) | ||
return Expressions.call(IgniteMath.class, "divideExact", left, right); | ||
|
||
return Expressions.makeBinary(ExpressionType.Divide, left, right); | ||
} | ||
|
||
/** Generate expression for method IgniteMath.negateExact() for integer subtypes. */ | ||
private static Expression negateExact(ExpressionType unaryType, Expression operand) { | ||
assert unaryType == ExpressionType.Negate || unaryType == ExpressionType.NegateChecked; | ||
|
||
Type opType = operand.getType(); | ||
|
||
if (opType == Integer.TYPE || opType == Long.TYPE || opType == Short.TYPE || opType == Byte.TYPE) | ||
return Expressions.call(IgniteMath.class, "negateExact", operand); | ||
|
||
return Expressions.makeUnary(unaryType, operand); | ||
} | ||
|
||
/** Generate expression for conversion from numeric primitive to numeric primitive with bounds check. */ | ||
public static Expression convertChecked(Expression exp, Primitive fromPrimitive, Primitive toPrimitive) { | ||
if (fromPrimitive.ordinal() <= toPrimitive.ordinal() || !toPrimitive.isFixedNumeric()) | ||
return Expressions.convert_(exp, toPrimitive.primitiveClass); | ||
|
||
return Expressions.call(IgniteMath.class, "convertTo" + | ||
SqlFunctions.initcap(toPrimitive.primitiveName) + "Exact", exp); | ||
} | ||
|
||
/** Generate expression for conversion from string to numeric primitive with bounds check. */ | ||
public static Expression parseStringChecked(Expression exp, Primitive toPrimitive) { | ||
return Expressions.call(IgniteMath.class, "convertTo" + | ||
SqlFunctions.initcap(toPrimitive.primitiveName) + "Exact", Expressions.new_(BigDecimal.class, exp)); | ||
} | ||
|
||
/** Generate expression for conversion from Number to numeric primitive with bounds check. */ | ||
public static Expression unboxChecked(Expression exp, @Nullable Primitive fromBox, Primitive toPrimitive) { | ||
if ((fromBox != null && fromBox.ordinal() <= toPrimitive.ordinal()) || !toPrimitive.isFixedNumeric()) | ||
return Expressions.unbox(exp, toPrimitive); | ||
|
||
return Expressions.call(IgniteMath.class, "convertTo" + | ||
SqlFunctions.initcap(toPrimitive.primitiveName) + "Exact", exp); | ||
} | ||
|
||
/** Find larger in type hierarchy. */ | ||
private static Primitive larger(Type type0, Type type1) { | ||
Primitive primitive0 = Primitive.ofBoxOr(type0); | ||
Primitive primitive1 = Primitive.ofBoxOr(type1); | ||
|
||
return primitive0.ordinal() > primitive1.ordinal() ? primitive0 : primitive1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.